diff options
author | Eric Wong <e@80x24.org> | 2016-07-03 00:43:12 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-07-03 00:43:30 +0000 |
commit | c1630b7dc4ef631250f77710b1c6cffea5e49b44 (patch) | |
tree | 986c76f5540bf8c89aa0896ef7cf8961b9f20012 /lib/PublicInbox/GitHTTPBackend.pm | |
parent | bfd60ef4c2eff566481f1e40b18b7c3d1b3e43fa (diff) | |
download | public-inbox-c1630b7dc4ef631250f77710b1c6cffea5e49b44.tar.gz |
This will allow cache proxies such as Varnish to avoid caching data sent by us.
Diffstat (limited to 'lib/PublicInbox/GitHTTPBackend.pm')
-rw-r--r-- | lib/PublicInbox/GitHTTPBackend.pm | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm index b4851920..a9c0e9c7 100644 --- a/lib/PublicInbox/GitHTTPBackend.pm +++ b/lib/PublicInbox/GitHTTPBackend.pm @@ -64,15 +64,29 @@ sub drop_client ($) { } } +my $prev = 0; +my $exp; +sub cache_one_year { + my ($h) = @_; + my $t = time + 31536000; + push @$h, 'Expires', $t == $prev ? $exp : ($exp = time2str($prev = $t)), + 'Cache-Control', 'public, max-age=31536000'; +} + sub serve_dumb { my ($env, $git, $path) = @_; my @h; my $type; - if ($path =~ /\A(?:$BIN)\z/o) { - $type = 'application/octet-stream'; - push @h, 'Expires', time2str(time + 31536000); - push @h, 'Cache-Control', 'public, max-age=31536000'; + if ($path =~ m!\Aobjects/[a-f0-9]{2}/[a-f0-9]{38}\z!) { + $type = 'application/x-git-loose-object'; + cache_one_year(\@h); + } elsif ($path =~ m!\Aobjects/pack/pack-[a-f0-9]{40}\.pack\z!) { + $type = 'application/x-git-packed-objects'; + cache_one_year(\@h); + } elsif ($path =~ m!\Aobjects/pack/pack-[a-f0-9]{40}\.idx\z!) { + $type = 'application/x-git-packed-objects-toc'; + cache_one_year(\@h); } elsif ($path =~ /\A(?:$TEXT)\z/o) { $type = 'text/plain'; push @h, @no_cache; |