Browse files

Make more files be served from /src as plain text.

  • Loading branch information...
1 parent 7be464c commit 0157c18cbc0835b627fa2e42b2433337f5f3fff5 @theory theory committed Apr 21, 2011
Showing with 10 additions and 3 deletions.
  1. +5 −0 Changes
  2. +4 −2 lib/PGXN/API/Router.pm
  3. +1 −1 t/router.t
View
5 Changes
@@ -1,5 +1,10 @@
Revision history for Perl extension PGXN::API
+0.12.2
+ - Changed the media type of many more files served from `src` to
+ text/plain. This is both for security reasons and so that files that
+ are plain text open in the browser rather than prompt to download.
+
0.12.1 2011-04-20T23:41:26
- Fixed rsync log parsing to properly detect when a file has been
changed. Previously, the code was only noticing new files.
View
6 lib/PGXN/API/Router.pm
@@ -98,10 +98,12 @@ sub app {
]
};
- # Disable HTML in /src.
+ # For source browsing, some things should be text/plain.
my $mimes = { %{ $Plack::MIME::MIME_TYPES } };
for my $ext (keys %{ $mimes }) {
- $mimes->{$ext} = 'text/plain' if $mimes->{$ext} =~ /html/;
+ $mimes->{$ext} = 'text/plain'
+ if $mimes->{$ext} =~ /html|x-c|xml|calendar|vcard/
+ || $ext ~~ [qw(.bat .css .eml .js .json .mime .swf)];
}
my $src_dir = Plack::App::Directory->new(
root => catdir $root, 'src'
View
2 t/router.t
@@ -122,7 +122,7 @@ test_psgi $app => sub {
ok $res->is_success, 'It should be a success';
is $res->header('X-PGXN-API-Version'), PGXN::API->VERSION,
'Should have API version in the header';
- is $res->content_type, 'application/json', 'Should be application/json';
+ is $res->content_type, 'text/plain', 'Should be text/plain';
};
# Try a src/readme file

0 comments on commit 0157c18

Please sign in to comment.