Skip to content

Commit

Permalink
Add Surrogate-Control for fastly caching on st.aticpan.org
Browse files Browse the repository at this point in the history
  • Loading branch information
ranguard committed Apr 13, 2014
1 parent d819cd6 commit 3c55985
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/MetaCPAN/Server/Controller/Source.pm
Expand Up @@ -33,6 +33,11 @@ sub get : Chained('index') : PathPart('') : Args {
}
else {
$c->stash->{path} = $file;
# Tell fastly to cache for a day (for st.aticpan.org,
# api.metacpan.org does not go through fastly)
my $max_age_seconds = 60 * 60 * 24;
$c->res->header('Surrogate-Control' => "max-age=${max_age_seconds}");
# Add X-Content-Type header, for fastly to rewrite on st.aticpan.org
$c->res->header( 'X-Content-Type' => Plack::MIME->mime_type($file) || 'text/plain' );
$c->res->content_type('text/plain');
$c->res->body( $file->openr );
Expand Down
5 changes: 5 additions & 0 deletions t/server/controller/source.t
Expand Up @@ -26,8 +26,13 @@ test_psgi app, sub {
'text/plain; charset=UTF-8',
'Content-type'
);
# Used for fastly on st.aticpan.org
is( $res->header('X-Content-Type'),
'text/x-script.perl-module', 'X-Content-Type' );

is( $res->header('Surrogate-Control'),
'max-age=86400', 'Surrogate-Control' );

}
elsif ( $k =~ /MANIFEST/ ) {

Expand Down

0 comments on commit 3c55985

Please sign in to comment.