X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FStatic%2FSimple.pm;h=ea5c86edb329298820f8d05f0f875bda5db3e196;hb=df755a7a2fe2851b9010f2cdbc48b8c494af89f0;hp=cab5625295c4eba7a40f73552d8eb8f018d655d7;hpb=7e76765e102658b7bdb1424d4de980484b8fa477;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Plugin/Static/Simple.pm b/lib/Catalyst/Plugin/Static/Simple.pm index cab5625..ea5c86e 100644 --- a/lib/Catalyst/Plugin/Static/Simple.pm +++ b/lib/Catalyst/Plugin/Static/Simple.pm @@ -4,22 +4,17 @@ use strict; use warnings; use base qw/Class::Accessor::Fast Class::Data::Inheritable/; use File::stat; +use File::Spec::Functions qw/catdir no_upwards splitdir/; use IO::File; use MIME::Types; use NEXT; -if ( Catalyst->VERSION le '5.33' ) { - require File::Slurp; -} - our $VERSION = '0.11'; __PACKAGE__->mk_classdata( qw/_static_mime_types/ ); __PACKAGE__->mk_accessors( qw/_static_file _static_debug_message/ ); -# prepare_action is used to first check if the request path is a static file. -# If so, we skip all other prepare_action steps to improve performance. sub prepare_action { my $c = shift; my $path = $c->req->path; @@ -53,7 +48,6 @@ sub prepare_action { return $c->NEXT::ACTUAL::prepare_action(@_); } -# dispatch takes the file found during prepare_action and serves it sub dispatch { my $c = shift; @@ -70,7 +64,6 @@ sub dispatch { } } -# finalize serves up final header information sub finalize { my $c = shift; @@ -92,6 +85,10 @@ sub setup { $c->NEXT::setup(@_); + if ( Catalyst->VERSION le '5.33' ) { + require File::Slurp; + } + $c->config->{static}->{dirs} ||= []; $c->config->{static}->{include_path} ||= [ $c->config->{root} ]; $c->config->{static}->{mime_types} ||= {}; @@ -100,7 +97,7 @@ sub setup { $c->config->{static}->{debug} ||= $c->debug; if ( ! defined $c->config->{static}->{no_logs} ) { $c->config->{static}->{no_logs} = 1; - } + } # load up a MIME::Types object, only loading types with # at least 1 file extension @@ -115,7 +112,7 @@ sub setup { sub _locate_static_file { my $c = shift; - my $path = $c->req->path; + my $path = catdir(no_upwards(splitdir( $c->req->path ))); my @ipaths = @{ $c->config->{static}->{include_path} }; my $dpaths; @@ -176,15 +173,6 @@ sub _serve_static { my $full_path = $c->_static_file; my $stat = stat $full_path; - # the below code all from C::P::Static - if ( $c->req->headers->if_modified_since ) { - if ( $c->req->headers->if_modified_since == $stat->mtime ) { - $c->res->status( 304 ); # Not Modified - $c->res->headers->remove_content_headers; - return 1; - } - } - $c->res->headers->content_type( $type ); $c->res->headers->content_length( $stat->size ); $c->res->headers->last_modified( $stat->mtime ); @@ -198,7 +186,7 @@ sub _serve_static { # new method, pass an IO::File object to body my $fh = IO::File->new( $full_path, 'r' ); if ( defined $fh ) { - $fh->binmode; + binmode $fh; $c->res->body( $fh ); } else { @@ -415,6 +403,28 @@ directory. This approach is recommended for production installations. SetHandler default-handler +=head1 INTERNAL EXTENDED METHODS + +Static::Simple extends the following steps in the Catalyst process. + +=head2 prepare_action + +prepare_action is used to first check if the request path is a static file. +If so, we skip all other prepare_action steps to improve performance. + +=head2 dispatch + +dispatch takes the file found during prepare_action and writes it to the +output. + +=head2 finalize + +finalize serves up final header information and displays any log messages. + +=head2 setup + +setup initializes all default values. + =head1 SEE ALSO L, L,