From: Andy Grundman Date: Mon, 24 Sep 2007 14:29:23 +0000 (+0000) Subject: Static::Simple 0.20, fixed static dirs regex and added content-type text/html to... X-Git-Tag: v0.21~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Static-Simple.git;a=commitdiff_plain;h=0495a29318d1867ec261ad7eb40192fdb12383e7 Static::Simple 0.20, fixed static dirs regex and added content-type text/html to 404 responses (Will Hawes) --- diff --git a/Changes b/Changes index a254033..14607ff 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,11 @@ Revision history for Perl extension Catalyst::Plugin::Static::Simple +0.20 2007-09-24 10:00:00 + - Fixed issue where the static dir regex did not add a trailing + slash so URLs such as /static1 were served as static when they + should be handled by Catalyst. (Will Hawes) + - Added text/html Content-Type to 404 responses. (Will Hawes) + 0.19 2007-07-02 17:00:00 - Fixed test failure on some systems in 11serve_static.t due to multiple MIME types defined for the extension '.pm'. diff --git a/lib/Catalyst/Plugin/Static/Simple.pm b/lib/Catalyst/Plugin/Static/Simple.pm index 1084945..7dbf37e 100644 --- a/lib/Catalyst/Plugin/Static/Simple.pm +++ b/lib/Catalyst/Plugin/Static/Simple.pm @@ -8,7 +8,7 @@ use File::Spec (); use IO::File (); use MIME::Types (); -our $VERSION = '0.19'; +our $VERSION = '0.20'; __PACKAGE__->mk_accessors( qw/_static_file _static_debug_message/ ); @@ -22,7 +22,11 @@ sub prepare_action { # is the URI in a static-defined path? foreach my $dir ( @{ $config->{dirs} } ) { my $dir_re = quotemeta $dir; - my $re = ( $dir =~ m{^qr/}xms ) ? eval $dir : qr/^${dir_re}/; + + # strip trailing slashes, they'll be added in our regex + $dir_re =~ s{/$}{}; + + my $re = ( $dir =~ m{^qr/}xms ) ? eval $dir : qr{^${dir_re}/}; if ($@) { $c->error( "Error compiling static dir regex '$dir': $@" ); } @@ -34,6 +38,7 @@ sub prepare_action { $c->_debug_msg( "404: file not found: $path" ) if $config->{debug}; $c->res->status( 404 ); + $c->res->content_type( 'text/html' ); } } } @@ -209,6 +214,7 @@ sub serve_static_file { $c->_debug_msg( "404: file not found: $full_path" ) if $config->{debug}; $c->res->status( 404 ); + $c->res->content_type( 'text/html' ); return; } diff --git a/t/05dirs.t b/t/05dirs.t index 8fdecca..acb299e 100644 --- a/t/05dirs.t +++ b/t/05dirs.t @@ -6,7 +6,7 @@ use warnings; use FindBin; use lib "$FindBin::Bin/lib"; -use Test::More tests => 10; +use Test::More tests => 13; use Catalyst::Test 'TestApp'; # test defined static dirs @@ -24,9 +24,10 @@ is( $res->content_type, 'text/plain', 'text/plain ok' ); ok( $res = request('http://localhost/always-static/test.html'), 'request ok' ); is( $res->code, 200, 'html file in dirs get served' ); -# a missing file in a defined static dir will return 404 +# a missing file in a defined static dir will return 404 and text/html ok( $res = request('http://localhost/always-static/404.txt'), 'request ok' ); is( $res->code, 404, '404 ok' ); +is( $res->content_type, 'text/html', '404 is text/html' ); # qr regex test ok( $res = request('http://localhost/images/catalyst.png'), 'request ok' ); @@ -35,3 +36,7 @@ is( $res->content_type, 'image/png', 'qr regex path ok' ); # eval regex test ok( $res = request('http://localhost/css/static.css'), 'request ok' ); like( $res->content, qr/background/, 'eval regex path ok' ); + +# A static dir with no trailing slash is handled by Cat +ok( $res = request('http://localhost/always-static'), 'request ok' ); +is( $res->content, 'default', 'content ok' ); \ No newline at end of file