diff options
author | W. Trevor King <wking@drexel.edu> | 2012-03-26 15:14:19 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-03-26 12:56:06 -0700 |
commit | 84d62947b59e1c49f36b77e2469b39723c503a39 (patch) | |
tree | 36e39b1d04a730554153a2419b31e7b12116d6ca /gitweb/gitweb.perl | |
parent | d037873021736010d1e9095fe9094f24d57b87c5 (diff) | |
download | git-wk/gitweb-snapshot-use-if-modified-since.tar.gz |
gitweb: add If-Modified-Since handling to git_snapshot().wk/gitweb-snapshot-use-if-modified-since
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 requested hash is a commit.
Requests for snapshots of tree-ishes, which lack well defined
timestamps, are still handled as they were before.
Signed-off-by: W Trevor King <wking@drexel.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'gitweb/gitweb.perl')
-rwxr-xr-x | gitweb/gitweb.perl | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 0fbb709def..976e581f07 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,10 +7064,19 @@ sub git_snapshot { } $filename =~ s/(["\\])/\\$1/g; - print $cgi->header( - -type => $known_snapshot_formats{$format}{'type'}, - -content_disposition => 'inline; filename="' . $filename . '"', - -status => '200 OK'); + if (%co) { + my %latest_date = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); + print $cgi->header( + -type => $known_snapshot_formats{$format}{'type'}, + -content_disposition => 'inline; filename="' . $filename . '"', + -last_modified => $latest_date{'rfc2822'}, + -status => '200 OK'); + } else { + print $cgi->header( + -type => $known_snapshot_formats{$format}{'type'}, + -content_disposition => 'inline; filename="' . $filename . '"', + -status => '200 OK'); + } open my $fd, "-|", $cmd or die_error(500, "Execute git-archive failed"); |