From: W. Trevor King <hidden> Date: 2016-06-15 22:53:24
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 <redacted>
---
gitweb/gitweb.perl | 10 +++++++++
t/t9501-gitweb-standalone-http-status.sh | 33 ++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)
I'm sorry to be bearer of bad news, but this is still incorrect.
It should be:
print $cgi->header(
-type => $known_snapshot_formats{$format}{'type'},
-content_disposition => 'inline; filename="' . $filename . '"',
+ %co ? (-last_modified => $latest_date{'rfc2822'}) : (),
-status => '200 OK');
(The "fat comma" => operator has relatively low priority, lower than
ternary conditional operator ?:)
And it was not caught by test because CGI.pm can output the last modified
header as "Last-modified" (RFC 2616, sec 4.2 states "Field names are
case-insensitive"), so the last check should be
+ ! grep -i "Last-Modified" gitweb.output
Hmmm... why we use gitweb.output and not gitweb.headers? Is it consistency
with earlier tests?
--
Jakub Narebski
Poland
I'm sorry to be bearer of bad news, but this is still incorrect.
It should be:
print $cgi->header(
-type => $known_snapshot_formats{$format}{'type'},
-content_disposition => 'inline; filename="' . $filename . '"',
+ %co ? (-last_modified => $latest_date{'rfc2822'}) : (),
-status => '200 OK');
Grr. Thanks. I'm getting lots of rebase practice on this patch set,
but I'm still missing things…
And it was not caught by test because CGI.pm can output the last modified
header as "Last-modified" (RFC 2616, sec 4.2 states "Field names are
case-insensitive"), so the last check should be
+ ! grep -i "Last-Modified" gitweb.output
Hmmm... why we use gitweb.output and not gitweb.headers? Is it consistency
with earlier tests?
Yes, but I can switch to `gitweb.headers` if you'd like. Should I
adjust all the header tests in t9501 to use `gitweb.headers` and `grep
-i`? It should probably be a separate patch for the tests that
existed before my i-m-s additions.
--
This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy
From: Jakub Narebski <hidden> Date: 2016-06-15 22:53:25
On Wed, 28 Mar 2012, W. Trevor King wrote:
On Wed, Mar 28, 2012 at 07:11:31PM +0100, Jakub Narebski wrote:
[...]
quoted
And it was not caught by test because CGI.pm can output the last modified
header as "Last-modified" (RFC 2616, sec 4.2 states "Field names are
case-insensitive"), so the last check should be
+ ! grep -i "Last-Modified" gitweb.output
Hmmm... why we use gitweb.output and not gitweb.headers? Is it consistency
with earlier tests?
Yes, but I can switch to `gitweb.headers` if you'd like. Should I
adjust all the header tests in t9501 to use `gitweb.headers` and `grep
-i`? It should probably be a separate patch for the tests that
existed before my i-m-s additions.
Eh, don't worry about this. First, I think we can assume that HTTP
headers from CGI.pm will all start with capital letter.
Second, for positive match being overly strict is safe - if assumption
doesn't hold we would get false failure. The problem is for negative
match - being overly strict means that we won't catch the breakage.
I think that the gitweb.output vs gitweb.headers (and gitweb.body) is
because those tests predate gitweb_run producing gitweb.headers file.
Be consistent if you want, or use new feature in new test; you don't
need to modernize t9501.
--
Jakub Narebski
Poland
From: W. Trevor King <hidden> Date: 2016-06-15 22:53:25
The current gitweb only generates Last-Modified and handles
If-Modified-Since headers for the git_feed action. This patch breaks
the Last-Modified and If-Modified-Since handling code out from
git_feed into a new function exit_if_unmodified_since. This makes the
code easy to reuse for other actions.
Only gitweb actions which can easily calculate a modification time
should use exit_if_unmodified_since, as the goal is to balance local
processing time vs. upload bandwidth.
Signed-off-by: W Trevor King <redacted>
---
gitweb/gitweb.perl | 57 +++++++++++++++--------------
t/t9501-gitweb-standalone-http-status.sh | 27 +++++++++++++-
2 files changed, 55 insertions(+), 29 deletions(-)
@@ -7003,6 +7003,28 @@ sub snapshot_name {returnwantarray?($name,$name):$name;}+subexit_if_unmodified_since{+my($latest_epoch)=@_;+our$cgi;++my$if_modified=$cgi->http('IF_MODIFIED_SINCE');+if(defined$if_modified){+my$since;+if(eval{requireHTTP::Date;1;}){+$since=HTTP::Date::str2time($if_modified);+}elsif(eval{requireTime::ParseDate;1;}){+$since=Time::ParseDate::parsedate($if_modified,GMT=>1);+}+if(defined$since&&$latest_epoch<=$since){+my%latest_date=parse_date($latest_epoch);+print$cgi->header(+-last_modified=>$latest_date{'rfc2822'},+-status=>'304 Not Modified');+gotoDONE_GITWEB;+}+}+}+subgit_snapshot{my$format=$input_params{'snapshot_format'};if(!@snapshot_fmts){
@@ -7820,35 +7842,14 @@ sub git_feed {if(defined($commitlist[0])){%latest_commit=%{$commitlist[0]};my$latest_epoch=$latest_commit{'committer_epoch'};-%latest_date=parse_date($latest_epoch,$latest_commit{'comitter_tz'});-my$if_modified=$cgi->http('IF_MODIFIED_SINCE');-if(defined$if_modified){-my$since;-if(eval{requireHTTP::Date;1;}){-$since=HTTP::Date::str2time($if_modified);-}elsif(eval{requireTime::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;-}-}-print$cgi->header(--type=>$content_type,--charset=>'utf-8',--last_modified=>$latest_date{'rfc2822'},--status=>'200 OK');-}else{-print$cgi->header(--type=>$content_type,--charset=>'utf-8',--status=>'200 OK');+exit_if_unmodified_since($latest_epoch);+%latest_date=parse_date($latest_epoch,$latest_commit{'comitter_tz'});}+print$cgi->header(+-type=>$content_type,+-charset=>'utf-8',+%latest_date?(-last_modified=>$latest_date{'rfc2822'}):(),+-status=>'200 OK');# Optimization: skip generating the body if client asks only# for Last-Modified date.
@@ -92,7 +92,7 @@ test_debug 'cat gitweb.output' test_expect_success'snapshots: bad tree-ish id (tagged object)''echoobject>tag-object&&gitaddtag-object&&-gitcommit-m"Object to be tagged"&&+test_tick&&gitcommit-m"Object to be tagged"&&gittagtagged-object`githash-objecttag-object`&&gitweb_run"p=.git;a=snapshot;h=tagged-object;sf=tgz"&&grep"400 - Object is not a tree-ish"gitweb.output
From: W. Trevor King <hidden> Date: 2016-06-15 22:53:25
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 <redacted>
---
gitweb/gitweb.perl | 10 +++++++++
t/t9501-gitweb-standalone-http-status.sh | 33 ++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 0 deletions(-)
From: W. Trevor King <hidden> Date: 2016-06-15 22:53:25
The git_feed() method was not setting a `Status` header unless it was
responding to an If-Modified-Since request with `304 Not Modified`.
Now, when it is serving successful responses, it sets status to `200
OK`.
Signed-off-by: W Trevor King <redacted>
---
gitweb/gitweb.perl | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
@@ -7841,11 +7841,13 @@ sub git_feed {print$cgi->header(-type=>$content_type,-charset=>'utf-8',--last_modified=>$latest_date{'rfc2822'});+-last_modified=>$latest_date{'rfc2822'},+-status=>'200 OK');}else{print$cgi->header(-type=>$content_type,--charset=>'utf-8');+-charset=>'utf-8',+-status=>'200 OK');}# Optimization: skip generating the body if client asks only
From: Jakub Narebski <hidden> Date: 2016-06-15 22:53:26
On Thu, 29 Mar 2012, W. Trevor King wrote:
The git_feed() method was not setting a `Status` header unless it was
responding to an If-Modified-Since request with `304 Not Modified`.
Now, when it is serving successful responses, it sets status to
`200 OK`.
Nice. This change is IMHO worth applying even without the rest of series.
So
Acked-by: Jakub Narebski [off-list ref]
You _might_ also add that this change would allow robust testing of
If-Modified-Since request handling in gitweb, but it is not really
necessary.
quoted hunk
Signed-off-by: W Trevor King <redacted>
---
gitweb/gitweb.perl | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
@@ -7841,11 +7841,13 @@ sub git_feed {print$cgi->header(-type=>$content_type,-charset=>'utf-8',--last_modified=>$latest_date{'rfc2822'});+-last_modified=>$latest_date{'rfc2822'},+-status=>'200 OK');}else{print$cgi->header(-type=>$content_type,--charset=>'utf-8');+-charset=>'utf-8',+-status=>'200 OK');}# Optimization: skip generating the body if client asks only
From: Jakub Narebski <hidden> Date: 2016-06-15 22:53:26
W. Trevor King wrote:
The current gitweb only generates Last-Modified and handles
If-Modified-Since headers for the git_feed action. This patch breaks
the Last-Modified and If-Modified-Since handling code out from
git_feed into a new function exit_if_unmodified_since. This makes the
code easy to reuse for other actions.
Only gitweb actions which can easily calculate a modification time
should use exit_if_unmodified_since, as the goal is to balance local
processing time vs. upload bandwidth.
Signed-off-by: W Trevor King <redacted>
Nice and clear.
Acked-by: Jakub Narebski [off-list ref]
Perhaps the second paragraph of the commit message would read better if
it started with "Note that only ..." or something like that, but this
is not that important, and not worth another round.
--
Jakub Narebski
Poland
From: Jakub Narebski <hidden> Date: 2016-06-15 22:53:26
On Thu, 29 Mar 2012, W. Trevor King wrote:
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.
If we ignore case, we can write
+ ! grep -i "Last-Modified:" gitweb.headers
which is IMVVVHO slightly more readable.
Not that it matters much. Just nitpicking.