From 30b1ffb460f3affd8d9044757838a89d3c4fae03 Mon Sep 17 00:00:00 2001 From: mwolson_admin Date: Sun, 22 Jun 2008 00:59:58 -0400 Subject: [PATCH] Implement cache of front page. --- gitweb.cgi | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/gitweb.cgi b/gitweb.cgi index ab8481b..5d244a7 100755 --- a/gitweb.cgi +++ b/gitweb.cgi @@ -58,6 +58,8 @@ our $site_header = ""; our $home_text = "indextext.html"; # filename of html text to include at bottom of each page our $site_footer = ""; +# filename of cached version of front page +our $cached_front_page = "/var/local/lib/gitweb/indexcache.html"; # URI of stylesheets our @stylesheets = ("gitweb.css"); @@ -422,6 +424,39 @@ if (defined $file_parent) { } } +sub git_send_cached_front_page { + my $status = shift || "200 OK"; + my $expires = shift; + my $content_type; + # require explicit support from the UA if we are to send the page as + # 'application/xhtml+xml', otherwise send it as plain old 'text/html'. + # we have to do this because MSIE sometimes globs '*/*', pretending to + # support xhtml+xml but choking when it gets what it asked for. + if (defined $cgi->http('HTTP_ACCEPT') && + $cgi->http('HTTP_ACCEPT') =~ m/(,|;|\s|^)application\/xhtml\+xml(,|;|\s|$)/ && + $cgi->Accept('application/xhtml+xml') != 0) { + $content_type = 'application/xhtml+xml'; + } else { + $content_type = 'text/html'; + } + print $cgi->header(-type=>$content_type, -charset => 'utf-8', + -status=> $status, -expires => $expires); + open (my $fd, $cached_front_page); + print <$fd>; + close $fd; + exit; +} + +# Display a cached page if no parameters were provided and the +# "nocache" parameter was not passed. +our $nocache = $cgi->param('nocache'); +our @params = $cgi->Vars; +use Data::Dumper; +if ($cached_front_page && ! defined $nocache && scalar @params == 0 + && -f $cached_front_page && -r $cached_front_page) { + git_send_cached_front_page(); +} + # parameters which are refnames our $hash = $cgi->param('h'); if (defined $hash) { -- 2.20.1