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

Re: [PATCHv2 6/6] gitweb: check if-modified-since for feeds

From
Jakub Narebski <jnareb@gmail.com>
Date
Feb 5, 2009, 02:03 UTC
Message-ID
<200902050303.43356.jnareb@gmail.com>
In-Reply-To
<1232970616-21167-7-git-send-email-giuseppe.bilotta@gmail.com>
On Mon, 26 Jan 2009, Giuseppe Bilotta wrote:
> 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.

It looks now quite nice, but I'd like to see information about dependencies for this feature in the commit message, something like:

   This feature (terminating early with '304 Not Modified' in response
   to 'If-Modified-Since' conditional request) requires having either
   HTTP::Date module (from libwww-perl) or Time::ParseDate module.
   If neither is present gitweb falls back to earlier behaviour of not
   reacting to 'If-Modified-Since'.

Note also (although I'm not sure if it is worth mentioning in commit message) that it doesn't save gitweb as much work as one could think, because at this place the whole list of commits is already generated and parsed. What we save is cost of running git-diff-tree for each commit (we could do better here, I think), and of course bandwidth.

I wonder if it would be possible to separate this code into subroutine, to make it possible to have support for "cache control" conditional requests also in other cases where it might help (for the future of course, not in this commit).

Perhaps if we run gitweb from Apache mod_perl in compatibility mode (ModPerl::Registry) to use Apache Perl API to respond to 'If-Modified-Since' ($r->is_fresh or something). But that is also just idea for the future improvement.

> 
> Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Here I think:
Acked-by: Jakub Narebski <jnareb@gmail.com>
Show 15 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..f4defb0 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);
Nitpick: either follow aligning on '=' characters, or skip it
altogether and always use one space before '=' in this fragment.
Show 17 quoted lines
> +		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);
> +			}
> +			if (defined $since && $latest_epoch <= $since) {
> +				print $cgi->header(
> +					-type => $content_type,
> +					-charset => 'utf-8',
> +					-last_modified => $latest_date{'rfc2822'},
> +					-status => '304 Not Modified');
> +				return;
> +			}
> +		}
Good.
Show 7 quoted lines
>  		print $cgi->header(
>  			-type => $content_type,
>  			-charset => 'utf-8',
> -- 
> 1.5.6.5
> 
> 
-- 
Jakub Narebski
Poland
Previous: Giuseppe BilottaNext: Giuseppe Bilotta
Message 8 of 37 in “[PATCHv2 0/6] gitweb: feed metadata enhancements”
  1. Giuseppe BilottaJan 26, 2009
  2. 1/6 gitweb: channel image in rss feedGiuseppe Bilotta, Jan 26, 2009
  3. 2/6 gitweb: feed generator metadataGiuseppe Bilotta, Jan 26, 2009
  4. 3/6 gitweb: rss feed managingEditorGiuseppe Bilotta, Jan 26, 2009
  5. 4/6 gitweb: rss channel dateGiuseppe Bilotta, Jan 26, 2009
  6. 5/6 gitweb: last-modified time should be commiter, not authorGiuseppe Bilotta, Jan 26, 2009
  7. 6/6 gitweb: check if-modified-since for feedsGiuseppe Bilotta, Jan 26, 2009
  8. Jakub NarebskiFeb 5, 2009
  9. Giuseppe BilottaFeb 6, 2009
  10. Jakub NarebskiFeb 4, 2009
  11. Giuseppe BilottaFeb 6, 2009
  12. Jakub NarebskiFeb 6, 2009
  13. Giuseppe BilottaFeb 6, 2009
  14. Deskin MillerFeb 11, 2009
  15. Giuseppe BilottaFeb 11, 2009
  16. Jakub NarebskiFeb 11, 2009
  17. Giuseppe BilottaFeb 11, 2009
  18. Deskin MillerFeb 12, 2009
  19. Jakub NarebskiFeb 12, 2009
  20. Giuseppe BilottaFeb 12, 2009
  21. Jakub NarebskiFeb 12, 2009
  22. Giuseppe BilottaFeb 12, 2009
  23. Jakub NarebskiFeb 4, 2009
  24. Giuseppe BilottaFeb 6, 2009
  25. Jakub NarebskiFeb 4, 2009
  26. Giuseppe BilottaFeb 6, 2009
  27. Jakub NarebskiFeb 4, 2009
  28. Giuseppe BilottaFeb 6, 2009
  29. Jakub NarebskiFeb 6, 2009
  30. Jakub NarebskiFeb 4, 2009
  31. Giuseppe BilottaFeb 6, 2009
  32. Junio C HamanoJan 28, 2009
  33. Jakub NarebskiJan 28, 2009
  34. Giuseppe BilottaJan 28, 2009
  35. Junio C HamanoJan 28, 2009
  36. Jakub NarebskiFeb 6, 2009
  37. Junio C HamanoFeb 7, 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.