From 8745db63ca65c28221229df3d945cb10045c29dc Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 29 Mar 2012 08:45:49 -0400 Subject: gitweb: add If-Modified-Since handling to git_snapshot(). Because snapshots can be large, you can save some bandwidth by supporting caching via If-Modified-Since. This patch adds support for the i-m-s request to git_snapshot() if the request is a commit. Requests for snapshots of trees, which lack well defined timestamps, are still handled as they were before. Signed-off-by: W Trevor King Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gitweb') diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 6d3f9c0a1c..ede804af3d 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -7051,6 +7051,10 @@ sub git_snapshot { my ($name, $prefix) = snapshot_name($project, $hash); my $filename = "$name$known_snapshot_formats{$format}{'suffix'}"; + + my %co = parse_commit($hash); + exit_if_unmodified_since($co{'committer_epoch'}) if %co; + my $cmd = quote_command( git_cmd(), 'archive', "--format=$known_snapshot_formats{$format}{'format'}", @@ -7060,9 +7064,15 @@ sub git_snapshot { } $filename =~ s/(["\\])/\\$1/g; + my %latest_date; + if (%co) { + %latest_date = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); + } + print $cgi->header( -type => $known_snapshot_formats{$format}{'type'}, -content_disposition => 'inline; filename="' . $filename . '"', + %co ? (-last_modified => $latest_date{'rfc2822'}) : (), -status => '200 OK'); open my $fd, "-|", $cmd -- cgit v1.2.3