Set Expires headers for Hydra's binary cache

This allows caching by reverse proxies.
This commit is contained in:
Eelco Dolstra 2014-11-06 14:31:04 +01:00
parent 55eb55478d
commit c250407f3c
4 changed files with 17 additions and 0 deletions

View file

@ -244,6 +244,7 @@ sub nix_cache_info :Path('nix-cache-info') :Args(0) {
# Give Hydra binary caches a very low priority (lower than the # Give Hydra binary caches a very low priority (lower than the
# static binary cache http://nixos.org/binary-cache). # static binary cache http://nixos.org/binary-cache).
"Priority: 100\n"; "Priority: 100\n";
setCacheHeaders($c, 365 * 24 * 60 * 60);
$c->forward('Hydra::View::Plain'); $c->forward('Hydra::View::Plain');
} }
@ -260,6 +261,7 @@ sub narinfo :LocalRegex('^([a-z0-9]+).narinfo$') :Args(0) {
$c->response->content_type('text/plain'); $c->response->content_type('text/plain');
$c->stash->{plain}->{data} = "does not exist\n"; $c->stash->{plain}->{data} = "does not exist\n";
$c->forward('Hydra::View::Plain'); $c->forward('Hydra::View::Plain');
setCacheHeaders($c, 60 * 60);
return; return;
} }

View file

@ -28,6 +28,7 @@ our @EXPORT = qw(
showJobName showJobName
showStatus showStatus
getResponsibleAuthors getResponsibleAuthors
setCacheHeaders
); );
@ -305,4 +306,12 @@ sub getResponsibleAuthors {
} }
# Set HTTP headers for the Nix binary cache.
sub setCacheHeaders {
my ($c, $expiration) = @_;
$c->response->headers->expires(time + $expiration);
delete $c->response->cookies->{hydra_session};
}
1; 1;

View file

@ -5,6 +5,7 @@ use base qw/Catalyst::View/;
use File::Basename; use File::Basename;
use Nix::Store; use Nix::Store;
use Nix::Crypto; use Nix::Crypto;
use Hydra::Helper::CatalystUtils;
sub process { sub process {
my ($self, $c) = @_; my ($self, $c) = @_;
@ -39,6 +40,8 @@ sub process {
$info .= "Signature: 1;$keyName;$sig\n"; $info .= "Signature: 1;$keyName;$sig\n";
} }
setCacheHeaders($c, 24 * 60 * 60);
$c->response->body($info); $c->response->body($info);
return 1; return 1;

View file

@ -2,6 +2,7 @@ package Hydra::View::NixNAR;
use strict; use strict;
use base qw/Catalyst::View/; use base qw/Catalyst::View/;
use Hydra::Helper::CatalystUtils;
sub process { sub process {
my ($self, $c) = @_; my ($self, $c) = @_;
@ -14,6 +15,8 @@ sub process {
open $fh, "nix-store --dump '$storePath' | bzip2 |"; open $fh, "nix-store --dump '$storePath' | bzip2 |";
setCacheHeaders($c, 365 * 24 * 60 * 60);
$c->response->body($fh); $c->response->body($fh);
return 1; return 1;