[Catalyst-commits] r8477 - in trunk/Catalyst-Plugin-PageCache: . lib/Catalyst/Plugin t

andyg at dev.catalyst.perl.org andyg at dev.catalyst.perl.org
Mon Sep 29 23:47:29 BST 2008


Author: andyg
Date: 2008-09-29 23:47:29 +0100 (Mon, 29 Sep 2008)
New Revision: 8477

Modified:
   trunk/Catalyst-Plugin-PageCache/Changes
   trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm
   trunk/Catalyst-Plugin-PageCache/t/07set_http_headers.t
Log:
Make header caching an off-by-default config option

Modified: trunk/Catalyst-Plugin-PageCache/Changes
===================================================================
--- trunk/Catalyst-Plugin-PageCache/Changes	2008-09-29 21:51:18 UTC (rev 8476)
+++ trunk/Catalyst-Plugin-PageCache/Changes	2008-09-29 22:47:29 UTC (rev 8477)
@@ -1,8 +1,8 @@
 Revision history for Perl extension Catalyst::Plugin::PageCache
 
 0.20    
-        - Cache HTTP headers to enable proper functionality behind edge
-          caches such as Akamai. (Chris Alef)
+        - Config option 'cache_headers' to cache HTTP headers.  This is needed
+          if operating behind edge caches such as Akamai. (Chris Alef)
         
 0.19    2008-08-22 13:00:00
         - Change config namespace to $c->config->{'Plugin::PageCache'}, old

Modified: trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm
===================================================================
--- trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm	2008-09-29 21:51:18 UTC (rev 8476)
+++ trunk/Catalyst-Plugin-PageCache/lib/Catalyst/Plugin/PageCache.pm	2008-09-29 22:47:29 UTC (rev 8477)
@@ -167,10 +167,12 @@
 sub _set_page_cache_headers {
     my ( $c, $data ) = @_;
 
-    for my $header_key ( keys %{ $data->{headers} || {} } ) {
-        $c->res->headers->header(
-            $header_key => $data->{headers}->{$header_key}
-        );
+    if ( $c->config->{'Plugin::PageCache'}->{cache_headers} ) {
+        for my $header_key ( keys %{ $data->{headers} || {} } ) {
+            $c->res->headers->header(
+                $header_key => $data->{headers}->{$header_key}
+            );
+        }
     }
     
     return unless $c->config->{'Plugin::PageCache'}->{set_http_headers};
@@ -264,11 +266,14 @@
                 || $c->res->headers->last_modified
                 || $now,
             expire_time => $now + $options->{cache_seconds},
-            headers     => {
+        };
+        
+        if ( $c->config->{'Plugin::PageCache'}->{cache_headers} ) {
+            $data->{headers} = {
                 map { $_ => $c->res->headers->header($_) }
                   $c->res->headers->header_field_names
-            },
-        };
+            };
+        }
 
         $data->{expires} = $options->{expires} if exists $options->{expires};
 
@@ -305,6 +310,7 @@
 
     $c->config->{'Plugin::PageCache'}->{auto_cache}       ||= [];
     $c->config->{'Plugin::PageCache'}->{expires}          ||= 60 * 5;
+    $c->config->{'Plugin::PageCache'}->{cache_headers}    ||= 0;
     $c->config->{'Plugin::PageCache'}->{set_http_headers} ||= 0;
     $c->config->{'Plugin::PageCache'}->{debug}            ||= $c->debug;
 
@@ -462,6 +468,12 @@
 This will set the default expiration time for all page caches.  If you do not
 specify this, expiration defaults to 300 seconds (5 minutes).
 
+    cache_headers => 1
+
+Enable this value if you need your cached responses to include custom HTTP
+headers set by your application.  This may be necessary if you operate behind
+an edge cache such as Akamai.
+
     set_http_headers => 1
 
 Enabling this value will cause Catalyst to set the correct HTTP headers to

Modified: trunk/Catalyst-Plugin-PageCache/t/07set_http_headers.t
===================================================================
--- trunk/Catalyst-Plugin-PageCache/t/07set_http_headers.t	2008-09-29 21:51:18 UTC (rev 8476)
+++ trunk/Catalyst-Plugin-PageCache/t/07set_http_headers.t	2008-09-29 22:47:29 UTC (rev 8477)
@@ -20,7 +20,8 @@
 
 use Catalyst::Test 'TestApp';
 
-# add config option
+# add config options
+TestApp->config->{'Plugin::PageCache'}->{cache_headers}    = 1;
 TestApp->config->{'Plugin::PageCache'}->{set_http_headers} = 1;
 
 # cache a page




More information about the Catalyst-commits mailing list