[Catalyst-commits] r7492 - in trunk/Catalyst-Engine-HTTP-Prefork: . lib/Catalyst/Engine/HTTP/Prefork

andyg at dev.catalyst.perl.org andyg at dev.catalyst.perl.org
Fri Mar 14 17:26:32 GMT 2008


Author: andyg
Date: 2008-03-14 17:26:31 +0000 (Fri, 14 Mar 2008)
New Revision: 7492

Modified:
   trunk/Catalyst-Engine-HTTP-Prefork/Makefile.PL
   trunk/Catalyst-Engine-HTTP-Prefork/lib/Catalyst/Engine/HTTP/Prefork/Handler.pm
Log:
Parse cookies with Cookie::XS

Modified: trunk/Catalyst-Engine-HTTP-Prefork/Makefile.PL
===================================================================
--- trunk/Catalyst-Engine-HTTP-Prefork/Makefile.PL	2008-03-13 05:48:22 UTC (rev 7491)
+++ trunk/Catalyst-Engine-HTTP-Prefork/Makefile.PL	2008-03-14 17:26:31 UTC (rev 7492)
@@ -4,6 +4,7 @@
 all_from 'lib/Catalyst/Engine/HTTP/Prefork.pm';
 
 requires 'Catalyst::Runtime'        => '5.7012';
+requires 'Cookie::XS'               => '0.07';
 requires 'HTTP::Body'               => '1.01';
 requires 'Net::Server'              => '0.97';
 # XXX: not released and may change namespaces

Modified: trunk/Catalyst-Engine-HTTP-Prefork/lib/Catalyst/Engine/HTTP/Prefork/Handler.pm
===================================================================
--- trunk/Catalyst-Engine-HTTP-Prefork/lib/Catalyst/Engine/HTTP/Prefork/Handler.pm	2008-03-13 05:48:22 UTC (rev 7491)
+++ trunk/Catalyst-Engine-HTTP-Prefork/lib/Catalyst/Engine/HTTP/Prefork/Handler.pm	2008-03-14 17:26:31 UTC (rev 7492)
@@ -3,6 +3,7 @@
 use strict;
 use base 'Catalyst::Engine::CGI';
 
+use Cookie::XS;
 use Data::Dump qw(dump);
 use HTTP::Body;
 use HTTP::Date qw(time2str);
@@ -37,6 +38,27 @@
     );
 }
 
+sub prepare_cookies {
+    my ( $self, $c ) = @_;
+
+    if ( my $header = $c->request->header('Cookie') ) {
+        # This method is around 8x faster than letting
+        # CGI::Simple::Cookie do the parsing in pure perl
+        my $cookies = Cookie::XS->parse( $header );
+        my $cookie_objs = { 
+            map {
+                $_ => bless {
+                    name  => $_,
+                    path  => '/',
+                    value => $cookies->{ $_ },
+                }, 'CGI::Simple::Cookie';
+            } keys %{ $cookies }
+        };
+        
+        $c->req->cookies( $cookie_objs );
+    }
+}
+
 # We need to override prepare_body for chunked request support.
 # This should probably move to Catalyst at some point.
 sub prepare_body {




More information about the Catalyst-commits mailing list