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'.
use IO::File ();
use MIME::Types ();
-our $VERSION = '0.19';
+our $VERSION = '0.20';
__PACKAGE__->mk_accessors( qw/_static_file _static_debug_message/ );
# 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': $@" );
}
$c->_debug_msg( "404: file not found: $path" )
if $config->{debug};
$c->res->status( 404 );
+ $c->res->content_type( 'text/html' );
}
}
}
$c->_debug_msg( "404: file not found: $full_path" )
if $config->{debug};
$c->res->status( 404 );
+ $c->res->content_type( 'text/html' );
return;
}
use FindBin;\r
use lib "$FindBin::Bin/lib";\r
\r
-use Test::More tests => 10;\r
+use Test::More tests => 13;\r
use Catalyst::Test 'TestApp';\r
\r
# test defined static dirs\r
ok( $res = request('http://localhost/always-static/test.html'), 'request ok' );\r
is( $res->code, 200, 'html file in dirs get served' );\r
\r
-# a missing file in a defined static dir will return 404\r
+# a missing file in a defined static dir will return 404 and text/html\r
ok( $res = request('http://localhost/always-static/404.txt'), 'request ok' );\r
is( $res->code, 404, '404 ok' );\r
+is( $res->content_type, 'text/html', '404 is text/html' );\r
\r
# qr regex test\r
ok( $res = request('http://localhost/images/catalyst.png'), 'request ok' );\r
# eval regex test\r
ok( $res = request('http://localhost/css/static.css'), 'request ok' );\r
like( $res->content, qr/background/, 'eval regex path ok' );\r
+\r
+# A static dir with no trailing slash is handled by Cat\r
+ok( $res = request('http://localhost/always-static'), 'request ok' );\r
+is( $res->content, 'default', 'content ok' );
\ No newline at end of file