[Catalyst-commits] r11329 -
Catalyst-Plugin-Static-Simple/branches/if_modified_since/lib/Catalyst/Plugin/Static
hobbs at dev.catalyst.perl.org
hobbs at dev.catalyst.perl.org
Mon Sep 7 11:27:48 GMT 2009
Author: hobbs
Date: 2009-09-07 11:27:47 +0000 (Mon, 07 Sep 2009)
New Revision: 11329
Modified:
Catalyst-Plugin-Static-Simple/branches/if_modified_since/lib/Catalyst/Plugin/Static/Simple.pm
Log:
Implement If-Modified-Since for Static::Simple
Modified: Catalyst-Plugin-Static-Simple/branches/if_modified_since/lib/Catalyst/Plugin/Static/Simple.pm
===================================================================
--- Catalyst-Plugin-Static-Simple/branches/if_modified_since/lib/Catalyst/Plugin/Static/Simple.pm 2009-09-07 11:27:17 UTC (rev 11328)
+++ Catalyst-Plugin-Static-Simple/branches/if_modified_since/lib/Catalyst/Plugin/Static/Simple.pm 2009-09-07 11:27:47 UTC (rev 11329)
@@ -169,24 +169,33 @@
sub _serve_static {
my $c = shift;
+ my $config = $c->config->{static};
my $full_path = shift || $c->_static_file;
my $type = $c->_ext_to_type( $full_path );
my $stat = stat $full_path;
+ my $ims = $c->req->headers->if_modified_since;
- $c->res->headers->content_type( $type );
- $c->res->headers->content_length( $stat->size );
- $c->res->headers->last_modified( $stat->mtime );
+ if (defined $ims && $stat->mtime <= $ims) {
+ $c->_debug_msg( " (not modified)" )
+ if $config->{debug};
- my $fh = IO::File->new( $full_path, 'r' );
- if ( defined $fh ) {
+ $c->res->status(304); # Not Modified
+ } else {
+ $c->res->headers->content_type( $type );
+ $c->res->headers->content_length( $stat->size );
+
+ my $fh = IO::File->new( $full_path, 'r' );
+ if ( defined $fh ) {
binmode $fh;
$c->res->body( $fh );
- }
- else {
+ }
+ else {
Catalyst::Exception->throw(
- message => "Unable to open $full_path for reading" );
+ message => "Unable to open $full_path for reading" );
+ }
}
+ $c->res->headers->last_modified( $stat->mtime );
return 1;
}
More information about the Catalyst-commits
mailing list