git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] gitweb: check if-modified-since for feeds

From
Jakub Narebski <jnareb@gmail.com>
Date
Jan 26, 2009, 02:18 UTC
Message-ID
<200901260318.05301.jnareb@gmail.com>
In-Reply-To
<1232923370-4427-2-git-send-email-giuseppe.bilotta@gmail.com>
Should be "[PATCH 2/2]" or similar, just in case.
On Sun, 25 Jun 2009, Giuseppe Bilotta wrote:
> Offering Last-modified header

And skipping generating the body if client uses 'HEAD' request to get only Last-Modified header.

>                              for feeds is only half the work: we should 
> also check that same date against If-modified-since, and bail out early
> with 304 Not Modified.
Lacks signoff.
Show 23 quoted lines
> ---
>  gitweb/gitweb.perl |   20 +++++++++++++++++++-
>  1 files changed, 19 insertions(+), 1 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 8c49c75..0a5d229 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -6015,7 +6015,25 @@ sub git_feed {
>  	}
>  	if (defined($commitlist[0])) {
>  		%latest_commit = %{$commitlist[0]};
> -		%latest_date   = parse_date($latest_commit{'committer_epoch'});
> +		my $latest_epoch = $latest_commit{'committer_epoch'};
> +		%latest_date   = parse_date($latest_epoch);
> +		my $if_modified = $cgi->http('IF_MODIFIED_SINCE');
> +		if (defined $if_modified) {
> +			my $since;
> +			if (eval { require HTTP::Date; 1; }) {
> +				$since = HTTP::Date::str2time($if_modified);
> +			} elsif (eval { require Time::ParseDate; 1; }) {
> +				$since = Time::ParseDate::parsedate($if_modified, GMT => 1);
> +			}

I'd really like to fallback on hand-parsing, as we have to parse date in well defined HTTP-date format (RFC-1123, update to RFC-822), which I think is what we send in Last-Modified header (or is it RFC-2822?).

But that might be too much work. I like the checking for modules, and the fallback cascade, but could you explain why in this order?

Show 6 quoted lines
> +			if (defined $since && $latest_epoch <= $since) {
> +				print $cgi->header(
> +					-type => $content_type,
> +					-charset => 'utf-8',
> +					-last_modified => $latest_date{'rfc2822'},
> +					-status => 304);

I think we spell HTTP status messages in full (even if it is hidden in die_error subroutine), i.e.

+					-status => '304 Not Modified');
Show 10 quoted lines
> +				return;
> +			}
> +		}
>  		print $cgi->header(
>  			-type => $content_type,
>  			-charset => 'utf-8',
> -- 
> 1.5.6.5
> 
> 

P.S. It would be nice to have this mechanism (responding to cache-control headers such as If-Modified-Since) for all of gitweb, but I guess it is most critical for feeds, which are _polled_.

-- 
Jakub Narebski
Poland
Previous: Giuseppe BilottaNext: Giuseppe Bilotta
Message 8 of 13 in “gitweb feed metadata tuneups”
  1. 0/4 gitweb feed metadata tuneupsGiuseppe Bilotta, Jan 23, 2009
  2. 1/4 gitweb: channel image in rss feedGiuseppe Bilotta, Jan 23, 2009
  3. 2/4 gitweb: feed generator metadataGiuseppe Bilotta, Jan 23, 2009
  4. 3/4 gitweb: rss feed managingEditorGiuseppe Bilotta, Jan 23, 2009
  5. 4/4 gitweb: rss channel dateGiuseppe Bilotta, Jan 23, 2009
  6. gitweb: last-modified time should be commiter, not authorGiuseppe Bilotta, Jan 25, 2009
  7. gitweb: check if-modified-since for feedsGiuseppe Bilotta, Jan 25, 2009
  8. Jakub NarebskiJan 26, 2009
  9. Giuseppe BilottaJan 26, 2009
  10. Jakub NarebskiFeb 2, 2009
  11. Jakub NarebskiJan 26, 2009
  12. Giuseppe BilottaJan 26, 2009
  13. Jakub NarebskiJan 24, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.