@@ -7004,6 +7004,28 @@ sub snapshot_name {
7004
7004
return wantarray ? ($name , $name ) : $name ;
7005
7005
}
7006
7006
7007
+ sub exit_if_unmodified_since {
7008
+ my ($latest_epoch ) = @_ ;
7009
+ our $cgi ;
7010
+
7011
+ my $if_modified = $cgi -> http(' IF_MODIFIED_SINCE' );
7012
+ if (defined $if_modified ) {
7013
+ my $since ;
7014
+ if (eval { require HTTP::Date; 1; }) {
7015
+ $since = HTTP::Date::str2time($if_modified );
7016
+ } elsif (eval { require Time::ParseDate; 1; }) {
7017
+ $since = Time::ParseDate::parsedate($if_modified , GMT => 1);
7018
+ }
7019
+ if (defined $since && $latest_epoch <= $since ) {
7020
+ my %latest_date = parse_date($latest_epoch );
7021
+ print $cgi -> header(
7022
+ -last_modified => $latest_date {' rfc2822' },
7023
+ -status => ' 304 Not Modified' );
7024
+ goto DONE_GITWEB;
7025
+ }
7026
+ }
7027
+ }
7028
+
7007
7029
sub git_snapshot {
7008
7030
my $format = $input_params {' snapshot_format' };
7009
7031
if (!@snapshot_fmts ) {
@@ -7030,6 +7052,10 @@ sub git_snapshot {
7030
7052
7031
7053
my ($name , $prefix ) = snapshot_name($project , $hash );
7032
7054
my $filename = " $name$known_snapshot_formats {$format }{'suffix'}" ;
7055
+
7056
+ my %co = parse_commit($hash );
7057
+ exit_if_unmodified_since($co {' committer_epoch' }) if %co ;
7058
+
7033
7059
my $cmd = quote_command(
7034
7060
git_cmd(), ' archive' ,
7035
7061
" --format=$known_snapshot_formats {$format }{'format'}" ,
@@ -7039,9 +7065,15 @@ sub git_snapshot {
7039
7065
}
7040
7066
7041
7067
$filename =~ s / (["\\ ])/ \\ $1 / g ;
7068
+ my %latest_date ;
7069
+ if (%co ) {
7070
+ %latest_date = parse_date($co {' committer_epoch' }, $co {' committer_tz' });
7071
+ }
7072
+
7042
7073
print $cgi -> header(
7043
7074
-type => $known_snapshot_formats {$format }{' type' },
7044
7075
-content_disposition => ' inline; filename="' . $filename . ' "' ,
7076
+ %co ? (-last_modified => $latest_date {' rfc2822' }) : (),
7045
7077
-status => ' 200 OK' );
7046
7078
7047
7079
open my $fd , " -|" , $cmd
@@ -7821,33 +7853,14 @@ sub git_feed {
7821
7853
if (defined ($commitlist [0])) {
7822
7854
%latest_commit = %{$commitlist [0]};
7823
7855
my $latest_epoch = $latest_commit {' committer_epoch' };
7824
- %latest_date = parse_date($latest_epoch , $latest_commit {' comitter_tz' });
7825
- my $if_modified = $cgi -> http(' IF_MODIFIED_SINCE' );
7826
- if (defined $if_modified ) {
7827
- my $since ;
7828
- if (eval { require HTTP::Date; 1; }) {
7829
- $since = HTTP::Date::str2time($if_modified );
7830
- } elsif (eval { require Time::ParseDate; 1; }) {
7831
- $since = Time::ParseDate::parsedate($if_modified , GMT => 1);
7832
- }
7833
- if (defined $since && $latest_epoch <= $since ) {
7834
- print $cgi -> header(
7835
- -type => $content_type ,
7836
- -charset => ' utf-8' ,
7837
- -last_modified => $latest_date {' rfc2822' },
7838
- -status => ' 304 Not Modified' );
7839
- return ;
7840
- }
7841
- }
7842
- print $cgi -> header(
7843
- -type => $content_type ,
7844
- -charset => ' utf-8' ,
7845
- -last_modified => $latest_date {' rfc2822' });
7846
- } else {
7847
- print $cgi -> header(
7848
- -type => $content_type ,
7849
- -charset => ' utf-8' );
7856
+ exit_if_unmodified_since($latest_epoch );
7857
+ %latest_date = parse_date($latest_epoch , $latest_commit {' comitter_tz' });
7850
7858
}
7859
+ print $cgi -> header(
7860
+ -type => $content_type ,
7861
+ -charset => ' utf-8' ,
7862
+ %latest_date ? (-last_modified => $latest_date {' rfc2822' }) : (),
7863
+ -status => ' 200 OK' );
7851
7864
7852
7865
# Optimization: skip generating the body if client asks only
7853
7866
# for Last-Modified date.
0 commit comments