Skip to content

Commit cd956c7

Browse files
Oblomovgitster
authored andcommitted
gitweb: check if-modified-since for feeds
Offering Last-modified header for feeds is only half the work, even if we bail out early on HEAD requests. We should also check that same date against If-modified-since, and bail out early with 304 Not Modified if that's the case. Signed-off-by: Giuseppe Bilotta <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2757b54 commit cd956c7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

gitweb/gitweb.perl

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6015,7 +6015,25 @@ sub git_feed {
60156015
}
60166016
if (defined($commitlist[0])) {
60176017
%latest_commit = %{$commitlist[0]};
6018-
%latest_date = parse_date($latest_commit{'committer_epoch'});
6018+
my $latest_epoch = $latest_commit{'committer_epoch'};
6019+
%latest_date = parse_date($latest_epoch);
6020+
my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
6021+
if (defined $if_modified) {
6022+
my $since;
6023+
if (eval { require HTTP::Date; 1; }) {
6024+
$since = HTTP::Date::str2time($if_modified);
6025+
} elsif (eval { require Time::ParseDate; 1; }) {
6026+
$since = Time::ParseDate::parsedate($if_modified, GMT => 1);
6027+
}
6028+
if (defined $since && $latest_epoch <= $since) {
6029+
print $cgi->header(
6030+
-type => $content_type,
6031+
-charset => 'utf-8',
6032+
-last_modified => $latest_date{'rfc2822'},
6033+
-status => '304 Not Modified');
6034+
return;
6035+
}
6036+
}
60196037
print $cgi->header(
60206038
-type => $content_type,
60216039
-charset => 'utf-8',

0 commit comments

Comments
 (0)