Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #605 from metacpan/haarg/improved-mime-types
use better content types for source requests
  • Loading branch information
ranguard committed Dec 21, 2016
2 parents 128339e + 7c23a0c commit 78b90c1
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/MetaCPAN/Server/Controller/Source.pm
Expand Up @@ -40,9 +40,19 @@ sub get : Chained('index') : PathPart('') : Args {
$c->stash->{path} = $file;

# 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');
my $type = Plack::MIME->mime_type($file) || 'text/plain';
$c->res->header( 'X-Content-Type' => $type );
if ( $type =~ m{^image/} ) {
$c->res->content_type($type);
}
elsif ( $type
=~ m{^(?:text/.*|application/javascript|application/json)$} )
{
$c->res->content_type('text/plain');
}
else {
$c->res->content_type('application/octet-stream');
}
$c->res->body( $file->openr );
}
}
Expand Down

0 comments on commit 78b90c1

Please sign in to comment.