[Catalyst-commits] r6348 - in trunk/Catalyst-Plugin-Static-Simple:
. lib/Catalyst/Plugin/Static t t/lib/TestApp/root/always-static
andyg at dev.catalyst.perl.org
andyg at dev.catalyst.perl.org
Mon Apr 30 17:22:13 GMT 2007
Author: andyg
Date: 2007-04-30 17:22:12 +0100 (Mon, 30 Apr 2007)
New Revision: 6348
Added:
trunk/Catalyst-Plugin-Static-Simple/t/lib/TestApp/root/always-static/test.html
Modified:
trunk/Catalyst-Plugin-Static-Simple/Changes
trunk/Catalyst-Plugin-Static-Simple/lib/Catalyst/Plugin/Static/Simple.pm
trunk/Catalyst-Plugin-Static-Simple/t/05dirs.t
Log:
Static::Simple 0.16 - fix 204/304 bug under mod_perl. Allow files in static dirs defined by 'dirs' to be served even if they match ignore_dirs or ignore_extensions
Modified: trunk/Catalyst-Plugin-Static-Simple/Changes
===================================================================
--- trunk/Catalyst-Plugin-Static-Simple/Changes 2007-04-30 15:27:51 UTC (rev 6347)
+++ trunk/Catalyst-Plugin-Static-Simple/Changes 2007-04-30 16:22:12 UTC (rev 6348)
@@ -1,5 +1,12 @@
Revision history for Perl extension Catalyst::Plugin::Static::Simple
+0.16
+ - Allow all files in directories defined by the config option 'dirs'
+ to be served as static even if the file matches ignore_dirs or
+ ignore_extensions.
+ - Fixed bug where 204 or 304 status codes would result in a 500 error
+ under mod_perl.
+
0.15 2006-12-08 22:30:00
- Quote metacharacters used in $c->config->{dirs} (Vlad Dan Dascalescu)
- store Mime::Types object in config hash instead of as classdata
Modified: trunk/Catalyst-Plugin-Static-Simple/lib/Catalyst/Plugin/Static/Simple.pm
===================================================================
--- trunk/Catalyst-Plugin-Static-Simple/lib/Catalyst/Plugin/Static/Simple.pm 2007-04-30 15:27:51 UTC (rev 6347)
+++ trunk/Catalyst-Plugin-Static-Simple/lib/Catalyst/Plugin/Static/Simple.pm 2007-04-30 16:22:12 UTC (rev 6348)
@@ -8,7 +8,7 @@
use IO::File ();
use MIME::Types ();
-our $VERSION = '0.15';
+our $VERSION = '0.16';
__PACKAGE__->mk_accessors( qw/_static_file _static_debug_message/ );
@@ -27,7 +27,7 @@
$c->error( "Error compiling static dir regex '$dir': $@" );
}
if ( $path =~ $re ) {
- if ( $c->_locate_static_file( $path ) ) {
+ if ( $c->_locate_static_file( $path, 1 ) ) {
$c->_debug_msg( 'from static directory' )
if $config->{debug};
} else {
@@ -71,11 +71,6 @@
$c->log->debug( 'Static::Simple: ' . join q{ }, @{$c->_debug_msg} );
}
- if ( $c->res->status =~ /^(1\d\d|[23]04)$/xms ) {
- $c->res->headers->remove_content_headers;
- return $c->finalize_headers;
- }
-
return $c->NEXT::ACTUAL::finalize(@_);
}
@@ -109,7 +104,7 @@
# Search through all included directories for the static file
# Based on Template Toolkit INCLUDE_PATH code
sub _locate_static_file {
- my ( $c, $path ) = @_;
+ my ( $c, $path, $in_static_dir ) = @_;
$path = File::Spec->catdir(
File::Spec->no_upwards( File::Spec->splitdir( $path ) )
@@ -136,22 +131,25 @@
$dir =~ s/(\/|\\)$//xms;
if ( -d $dir && -f $dir . '/' . $path ) {
- # do we need to ignore the file?
- for my $ignore ( @{ $config->{ignore_dirs} } ) {
- $ignore =~ s{(/|\\)$}{};
- if ( $path =~ /^$ignore(\/|\\)/ ) {
- $c->_debug_msg( "Ignoring directory `$ignore`" )
- if $config->{debug};
- next DIR_CHECK;
+ # Don't ignore any files in static dirs defined with 'dirs'
+ unless ( $in_static_dir ) {
+ # do we need to ignore the file?
+ for my $ignore ( @{ $config->{ignore_dirs} } ) {
+ $ignore =~ s{(/|\\)$}{};
+ if ( $path =~ /^$ignore(\/|\\)/ ) {
+ $c->_debug_msg( "Ignoring directory `$ignore`" )
+ if $config->{debug};
+ next DIR_CHECK;
+ }
}
- }
- # do we need to ignore based on extension?
- for my $ignore_ext ( @{ $config->{ignore_extensions} } ) {
- if ( $path =~ /.*\.${ignore_ext}$/ixms ) {
- $c->_debug_msg( "Ignoring extension `$ignore_ext`" )
- if $config->{debug};
- next DIR_CHECK;
+ # do we need to ignore based on extension?
+ for my $ignore_ext ( @{ $config->{ignore_extensions} } ) {
+ if ( $path =~ /.*\.${ignore_ext}$/ixms ) {
+ $c->_debug_msg( "Ignoring extension `$ignore_ext`" )
+ if $config->{debug};
+ next DIR_CHECK;
+ }
}
}
Modified: trunk/Catalyst-Plugin-Static-Simple/t/05dirs.t
===================================================================
--- trunk/Catalyst-Plugin-Static-Simple/t/05dirs.t 2007-04-30 15:27:51 UTC (rev 6347)
+++ trunk/Catalyst-Plugin-Static-Simple/t/05dirs.t 2007-04-30 16:22:12 UTC (rev 6348)
@@ -6,7 +6,7 @@
use FindBin;
use lib "$FindBin::Bin/lib";
-use Test::More tests => 8;
+use Test::More tests => 10;
use Catalyst::Test 'TestApp';
# test defined static dirs
@@ -20,6 +20,10 @@
ok( my $res = request('http://localhost/always-static/test'), 'request ok' );
is( $res->content_type, 'text/plain', 'text/plain ok' );
+# a file with an extension in ignore_extensions still gets served
+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
ok( $res = request('http://localhost/always-static/404.txt'), 'request ok' );
is( $res->code, 404, '404 ok' );
Added: trunk/Catalyst-Plugin-Static-Simple/t/lib/TestApp/root/always-static/test.html
===================================================================
--- trunk/Catalyst-Plugin-Static-Simple/t/lib/TestApp/root/always-static/test.html (rev 0)
+++ trunk/Catalyst-Plugin-Static-Simple/t/lib/TestApp/root/always-static/test.html 2007-04-30 16:22:12 UTC (rev 6348)
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>test</title>
+ </head>
+ <body>
+ <div>test</div>
+ </body>
+</html>
Property changes on: trunk/Catalyst-Plugin-Static-Simple/t/lib/TestApp/root/always-static/test.html
___________________________________________________________________
Name: svn:mime-type
+ text/html
Name: svn:keywords
+ Id Author LastChangedDate LastChangedBy
Name: svn:eol-style
+ native
More information about the Catalyst-commits
mailing list