[Catalyst-commits] r11326 - in Catalyst-Plugin-Static-Simple: . branches branches/if_modified_since branches/if_modified_since/lib/Catalyst/Plugin/Static

hobbs at dev.catalyst.perl.org hobbs at dev.catalyst.perl.org
Mon Sep 7 11:19:38 GMT 2009


Author: hobbs
Date: 2009-09-07 11:19:38 +0000 (Mon, 07 Sep 2009)
New Revision: 11326

Added:
   Catalyst-Plugin-Static-Simple/branches/
   Catalyst-Plugin-Static-Simple/branches/if_modified_since/
Modified:
   Catalyst-Plugin-Static-Simple/branches/if_modified_since/lib/Catalyst/Plugin/Static/Simple.pm
Log:
Add If-Modified-Since support to Static::Simple


Copied: Catalyst-Plugin-Static-Simple/branches/if_modified_since (from rev 11325, Catalyst-Plugin-Static-Simple/trunk)


Property changes on: Catalyst-Plugin-Static-Simple/branches/if_modified_since
___________________________________________________________________
Name: svn:ignore
   + META.yml
pm_to_blib
blib
inc
Makefile
MANIFEST
MANIFEST.bak
Makefile.old

Name: svn:mergeinfo
   + 
Name: svk:merge
   + 8a9521aa-ff93-41d6-9f87-b05cafcdab40:/local/cat/Catalyst-Plugin-Static-Simple:8155

Modified: Catalyst-Plugin-Static-Simple/branches/if_modified_since/lib/Catalyst/Plugin/Static/Simple.pm
===================================================================
--- Catalyst-Plugin-Static-Simple/trunk/lib/Catalyst/Plugin/Static/Simple.pm	2009-09-05 15:21:21 UTC (rev 11325)
+++ Catalyst-Plugin-Static-Simple/branches/if_modified_since/lib/Catalyst/Plugin/Static/Simple.pm	2009-09-07 11:19:38 UTC (rev 11326)
@@ -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