]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: add If-Modified-Since handling to git_snapshot().
authorW. Trevor King <redacted>
Thu, 29 Mar 2012 12:45:49 +0000 (08:45 -0400)
committerLady <redacted>
Mon, 6 Apr 2026 04:51:32 +0000 (00:51 -0400)
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 <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl

index 349a7d22f4a9ec4bd421111ae501f7f351dc632160d4ea03bbc51db2afe28452..351f524ee1fdde0391450146bf8fff3babceaaf5e9604e0e041267a21d98b021 100755 (executable)
@@ -7052,6 +7052,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'}",
@@ -7061,9 +7065,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
This page took 0.316643 seconds and 4 git commands to generate.