Fixed multiple header bug
Sebastian Riedel [Tue, 15 Nov 2005 12:51:29 +0000 (12:51 +0000)]
Changes
lib/Catalyst.pm
lib/Catalyst/Engine.pm
lib/Catalyst/Engine/Test.pm
lib/Catalyst/Test.pm
t/live/engine/response/cookies.t

diff --git a/Changes b/Changes
index 4c465f5..ff8f7e1 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 This file documents the revision history for Perl extension Catalyst.
 
+5.55    2005-11-15 12:55:00
+        - Fixed multiple cookie handling
+
 5.54    2005-11-14 22:55:00
         - Fixed a Module::Pluggable::Fast related bug
 
index 2d26d27..c661d72 100644 (file)
@@ -54,7 +54,7 @@ __PACKAGE__->engine_class('Catalyst::Engine::CGI');
 __PACKAGE__->request_class('Catalyst::Request');
 __PACKAGE__->response_class('Catalyst::Response');
 
-our $VERSION = '5.54';
+our $VERSION = '5.55';
 
 sub import {
     my ( $class, @arguments ) = @_;
index 920fe0e..7f0a11b 100644 (file)
@@ -78,8 +78,8 @@ sub finalize_cookies {
         push @cookies, $cookie->as_string;
     }
 
-    if (@cookies) {
-        $c->res->headers->push_header( 'Set-Cookie' => join ',', @cookies );
+    for my $cookie (@cookies) {
+        $c->res->headers->push_header( 'Set-Cookie' => $cookie );
     }
 }
 
index 452cc2d..0f452fc 100644 (file)
@@ -3,6 +3,7 @@ package Catalyst::Engine::Test;
 use strict;
 use base 'Catalyst::Engine::CGI';
 use Catalyst::Utils;
+use HTTP::Headers;
 use HTTP::Response;
 use HTTP::Status;
 use NEXT;
@@ -66,10 +67,10 @@ sub run {
 
     # We emulate CGI
     local %ENV = (
-        PATH_INFO       => $request->uri->path  || '',
-        QUERY_STRING    => $request->uri->query || '',
-        REMOTE_ADDR     => '127.0.0.1',
-        REMOTE_HOST     => 'localhost',
+        PATH_INFO    => $request->uri->path  || '',
+        QUERY_STRING => $request->uri->query || '',
+        REMOTE_ADDR  => '127.0.0.1',
+        REMOTE_HOST  => 'localhost',
         REQUEST_METHOD  => $request->method,
         SERVER_NAME     => 'localhost',
         SERVER_PORT     => $request->uri->port,
index d565abf..3af0f15 100644 (file)
@@ -1,13 +1,31 @@
 package Catalyst::Test;
 
 use strict;
+use warnings;
 
 use Catalyst::Exception;
 use Catalyst::Utils;
 use UNIVERSAL::require;
+use HTTP::Headers;
 
 $ENV{CATALYST_ENGINE} = 'Test';
 
+# Bypass a HTTP::Headers bug
+{
+    no warnings 'redefine';
+
+    sub HTTP::Headers::new {
+        my $class = shift;
+        my $self = bless {}, $class;
+        if (@_) {
+            while ( my ( $field, $val ) = splice( @_, 0, 2 ) ) {
+                $self->push_header( $field, $val );
+            }
+        }
+        return $self;
+    }
+}
+
 =head1 NAME
 
 Catalyst::Test - Test Catalyst applications
index 410e351..0ed7e91 100644 (file)
@@ -8,12 +8,11 @@ use lib "$FindBin::Bin/../../lib";
 
 use Test::More tests => 10;
 use Catalyst::Test 'TestApp';
-
 use HTTP::Headers::Util 'split_header_words';
 
 my $expected = {
-    Catalyst => [qw( Catalyst Cool path / )],
-    Cool     => [qw( Cool Catalyst path / )]
+    Catalyst => [qw|Catalyst Cool path /|],
+    Cool     => [qw|Cool Catalyst path /|]
 };
 
 {
@@ -26,8 +25,9 @@ my $expected = {
 
     my $cookies = {};
 
-    for my $cookie ( split_header_words( $response->header('Set-Cookie') ) ) {
-        $cookies->{ $cookie->[0] } = $cookie;
+    for my $string ( $response->header('Set-Cookie') ) {
+        my $cookie = [ split_header_words $string];
+        $cookies->{ $cookie->[0]->[0] } = $cookie->[0];
     }
 
     is_deeply( $cookies, $expected, 'Response Cookies' );
@@ -43,8 +43,9 @@ my $expected = {
 
     my $cookies = {};
 
-    for my $cookie ( split_header_words( $response->header('Set-Cookie') ) ) {
-        $cookies->{ $cookie->[0] } = $cookie;
+    for my $string ( $response->header('Set-Cookie') ) {
+        my $cookie = [ split_header_words $string];
+        $cookies->{ $cookie->[0]->[0] } = $cookie->[0];
     }
 
     is_deeply( $cookies, $expected, 'Response Cookies' );