user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] git-http-backend: set cache headers
@ 2016-05-15 23:52  7% Eric Wong
  0 siblings, 0 replies; 1+ results
From: Eric Wong @ 2016-05-15 23:52 UTC (permalink / raw)
  To: meta

Mostly stolen from git upstream, these should prevent any caches
such as varnish or squid from acting improperly.
---
 lib/PublicInbox/GitHTTPBackend.pm | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index abb70df..b58cc30 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -9,6 +9,7 @@ use warnings;
 use Fcntl qw(:seek);
 use IO::File;
 use PublicInbox::Spawn qw(spawn);
+use HTTP::Date qw(time2str);
 
 # TODO: make configurable, but keep in mind it's better to have
 # multiple -httpd worker processes which are already scaled to
@@ -33,6 +34,10 @@ our $ANY = join('|', @binary, @text);
 my $BIN = join('|', @binary);
 my $TEXT = join('|', @text);
 
+my @no_cache = ('Expires', 'Fri, 01 Jan 1980 00:00:00 GMT',
+		'Pragma', 'no-cache',
+		'Cache-Control', 'no-cache, max-age=0, must-revalidate');
+
 my $nextq;
 sub do_next () {
 	my $q = $nextq;
@@ -42,8 +47,9 @@ sub do_next () {
 	}
 }
 
-sub r {
-	[ $_[0] , [qw(Content-Type text/plain Content-Length 0) ], [] ]
+sub r ($) {
+	my ($s) = @_;
+	[ $s, [qw(Content-Type text/plain Content-Length 0), @no_cache ], [] ]
 }
 
 sub serve {
@@ -73,11 +79,15 @@ sub drop_client ($) {
 sub serve_dumb {
 	my ($cgi, $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';
 	} elsif ($path =~ /\A(?:$TEXT)\z/o) {
 		$type = 'text/plain';
+		push @h, @no_cache;
 	} else {
 		return r(404);
 	}
@@ -125,7 +135,7 @@ sub serve_dumb {
 	};
 
 	my $code = 200;
-	my @h = ('Content-Type', $type);
+	push @h, 'Content-Type', $type;
 	my $range = $env->{HTTP_RANGE};
 	if (defined $range && $range =~ /\bbytes=(\d*)-(\d*)\z/) {
 		($code, $len) = prepare_range($cgi, $in, \@h, $1, $2, $size);

^ permalink raw reply related	[relevance 7%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-05-15 23:52  7% [PATCH] git-http-backend: set cache headers Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).