@matheusbsbs / matheus-bagliano / commits / cd956c73a2
Fork 0

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 <giuseppe.bilotta@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Giuseppe Bilotta committed Jan 26, 2009 at 12:50 UTC cd956c73a2cce6613a6cd19df6ccb9ff1b08f79a
1 file changed +19 -1
gitweb/gitweb.perl
+19 -1
@@ -6015,7 +6015,25 @@ sub git_feed {
6015 }
6016 if (defined($commitlist[0])) {
6017 %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 + }
6037 print $cgi->header(
6038 -type => $content_type,
6039 -charset => 'utf-8',