[Jifty-commit] r2478 - jifty/trunk/lib/Jifty/View/Static

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon Jan 8 06:18:37 EST 2007


Author: clkao
Date: Mon Jan  8 06:18:23 2007
New Revision: 2478

Modified:
   jifty/trunk/lib/Jifty/View/Static/Handler.pm

Log:
Actually implement if-modified-since for static view handler.

Modified: jifty/trunk/lib/Jifty/View/Static/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/View/Static/Handler.pm	(original)
+++ jifty/trunk/lib/Jifty/View/Static/Handler.pm	Mon Jan  8 06:18:23 2007
@@ -28,7 +28,7 @@
     * How do we merge together the two static roots?
 * If static files go through Jifty::Handler
     * We need a flag to allow them to go through the dispatcher, too
-    * return "True" (304) for if-modified-since unless develmode.
+    * return "True" (304) for if-modified-since
     * if the browser accepts gzipped data,
         see if we have a cached gzipped copy
             if so, send it
@@ -67,17 +67,19 @@
     my $self = shift;
     my $path = shift;
 
-    #if ( Jifty->handler->cgi->http('If-Modified-Since') and not Jifty->config->framework('DevelMode') ) { $self->respond_not_modified(); }
-    my $local_path = $self->file_path($path);
-    unless ($local_path) {
-        return undef;
+    my $local_path = $self->file_path($path) or return undef;
+
+    if ( my $since = Jifty->handler->cgi->http('If-Modified-Since') ) {
+        my @file_info = stat($local_path);
+        return $self->send_not_modified
+            unless $file_info[9] > HTTP::Date::str2time($since);
     }
     my $mime_type = $self->mime_type($local_path);
-    
+
     if ( $self->client_accepts_gzipped_content and $mime_type =~ m!^(text/|application/x-javascript)! ) {
         return $self->send_file($local_path, $mime_type, 'gzip');
     } else {
-        return  $self->send_file($local_path, $mime_type, 'uncompressed');
+        return $self->send_file($local_path, $mime_type, 'uncompressed');
     }
 
 }
@@ -228,7 +230,9 @@
 
 sub send_not_modified {
     my $self = shift;
-    Jifty->handler->apache->header_out( Status => 304 );
+    my $apache = Jifty->handler->apache;
+    $apache->header_out( Status => 304 );
+    $apache->send_http_header();
     return 1;
 
 }


More information about the Jifty-commit mailing list