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

Re: [PATCH v6 3/3] gitweb: add If-Modified-Since handling to git_snapshot().

From
Jakub Narebski <jnareb@gmail.com>
Date
Mar 28, 2012, 16:08 UTC
Message-ID
<201203281808.56432.jnareb@gmail.com>
In-Reply-To
<8129a671c793613ad2a0b00e1239e6a7ded7491a.1332949186.git.wking@drexel.edu>
On Wed, 28 Mar 2012, wking@tremily.us wrote:
Show 24 quoted lines
> Because snapshots can be large, you can save some bandwidth by
> supporting caching via If-Modified-Since.  This patch adds support for
> the i-m-s request to git_snapshot() if the request is a commit.
> Requests for snapshots of trees, which lack well defined timestamps,
> are still handled as they were before.
> 
> Signed-off-by: W Trevor King <wking@drexel.edu>
> ---
>  gitweb/gitweb.perl                       |   10 +++++++++
>  t/t9501-gitweb-standalone-http-status.sh |   33 ++++++++++++++++++++++++++++++
>  2 files changed, 43 insertions(+), 0 deletions(-)
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index ba106c1..591c793 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -7051,6 +7051,10 @@ sub git_snapshot {
>  
>  	my ($name, $prefix) = snapshot_name($project, $hash);
>  	my $filename = "$name$known_snapshot_formats{$format}{'suffix'}";
> +
> +	my %co = parse_commit($hash);
> +	exit_if_unmodified_since($co{'committer_epoch'}) if %co;
> +
Nice.
Show 12 quoted lines
>  	my $cmd = quote_command(
>  		git_cmd(), 'archive',
>  		"--format=$known_snapshot_formats{$format}{'format'}",
> @@ -7060,9 +7064,15 @@ sub git_snapshot {
>  	}
>  
>  	$filename =~ s/(["\\])/\\$1/g;
> +	my %latest_date;
> +	if (%co) {
> +		%latest_date = parse_date($co{'committer_epoch'}, $co{'committer_tz'});
> +	}
> +
That is probably more readable than
  +	%latest_date = parse_date($co{'committer_epoch'}, $co{'committer_tz'})
  +		if %co;
Show 6 quoted lines
>  	print $cgi->header(
>  		-type => $known_snapshot_formats{$format}{'type'},
>  		-content_disposition => 'inline; filename="' . $filename . '"',
> +		-last_modified => (%co ? $latest_date{'rfc2822'} : undef),
>  		-status => '200 OK');
>  
Same issue as with previous patch:
   	print $cgi->header(
   		-type => $known_snapshot_formats{$format}{'type'},
   		-content_disposition => 'inline; filename="' . $filename . '"',
  +		%co ? (-last_modified => $latest_date{'rfc2822'}) : (),
   		-status => '200 OK');
Show 41 quoted lines
>  	open my $fd, "-|", $cmd
> diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh
> index afa6bd4..1487820 100755
> --- a/t/t9501-gitweb-standalone-http-status.sh
> +++ b/t/t9501-gitweb-standalone-http-status.sh
> @@ -138,6 +138,39 @@ test_expect_success 'modification: feed if-modified-since (unmodified)' '
>  '
>  test_debug 'cat gitweb.headers'
>  
> +test_expect_success 'modification: snapshot last-modified' '
> +	gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
> +	grep "Status: 200 OK" gitweb.output &&
> +	grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.output
> +'
> +test_debug 'cat gitweb.headers'
> +
> +test_expect_success 'modification: snapshot if-modified-since (modified)' '
> +	export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
> +	test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
> +	gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
> +	grep "Status: 200 OK" gitweb.output
> +'
> +test_debug 'cat gitweb.headers'
> +
> +test_expect_success 'modification: snapshot if-modified-since (unmodified)' '
> +	export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
> +	test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
> +	gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
> +	grep "Status: 304 Not Modified" gitweb.output
> +'
> +test_debug 'cat gitweb.headers'
> +
> +test_expect_success 'modification: tree snapshot' '
> +	ID=`git rev-parse --verify HEAD^{tree}` &&
> +	export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
> +	test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
> +	gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
> +	grep "Status: 200 OK" gitweb.output &&
> +	! grep "Last-Modified" gitweb.output
> +'
> +test_debug 'cat gitweb.headers'
Good!
-- 
Jakub Narebski
Poland
Previous: wking@tremily.usNext: W. Trevor King
Message 34 of 43 in “What's cooking in git.git (Mar 2012, #07; Mon, 19)”
  1. Junio C HamanoMar 20, 2012
  2. W. Trevor KingMar 20, 2012
  3. Junio C HamanoMar 20, 2012
  4. Incremental updates to What's cookingJunio C Hamano, Mar 20, 2012
  5. Isolate If-Modified-Since handling in gitwebW. Trevor King, Mar 21, 2012
  6. Jakub NarebskiMar 21, 2012
  7. W. Trevor KingMar 21, 2012
  8. Jakub NarebskiMar 21, 2012
  9. W. Trevor KingMar 21, 2012
  10. Junio C HamanoMar 21, 2012
  11. W. Trevor KingMar 21, 2012
  12. Jakub NarebskiMar 21, 2012
  13. Junio C HamanoMar 21, 2012
  14. W. Trevor KingMar 21, 2012
  15. Jakub NarebskiMar 22, 2012
  16. Junio C HamanoMar 21, 2012
  17. Jakub NarebskiMar 22, 2012
  18. Junio C HamanoMar 22, 2012
  19. W. Trevor KingMar 26, 2012
  20. 1/3 gitweb: add `status` headers to git_feed() responses.W. Trevor King, Mar 26, 2012
  21. 2/3 gitweb: refactor If-Modified-Since handlingW. Trevor King, Mar 26, 2012
  22. Junio C HamanoMar 26, 2012
  23. W. Trevor KingMar 26, 2012
  24. Junio C HamanoMar 26, 2012
  25. W. Trevor KingMar 26, 2012
  26. Jakub NarebskiMar 27, 2012
  27. W. Trevor KingMar 28, 2012
  28. Jakub NarebskiMar 28, 2012
  29. 0/3 gitweb: refactor If-Modified-Since handlingwking@tremily.us, Mar 28, 2012
  30. W. Trevor KingMar 28, 2012
  31. 1/3 gitweb: add `status` headers to git_feed() responses.wking@tremily.us, Mar 28, 2012
  32. 2/3 gitweb: refactor If-Modified-Since handlingwking@tremily.us, Mar 28, 2012
  33. 3/3 gitweb: add If-Modified-Since handling to git_snapshot().wking@tremily.us, Mar 28, 2012
  34. Jakub NarebskiMar 28, 2012
  35. W. Trevor KingMar 26, 2012
  36. Jakub NarebskiMar 27, 2012
  37. W. Trevor KingMar 28, 2012
  38. 3/3 gitweb: add If-Modified-Since handling to git_snapshot().W. Trevor King, Mar 26, 2012
  39. Jakub NarebskiMar 27, 2012
  40. W. Trevor KingMar 27, 2012
  41. Jakub NarebskiMar 27, 2012
  42. W. Trevor KingMar 27, 2012
  43. Junio C HamanoMar 27, 2012

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.