[Dancer-users] Cookies in Dancer 1.3011

Alex Khrenov sapsan at gmail.com
Tue Feb 22 13:39:20 CET 2011


When i try to set several cookies, i have trouble: only 1 cookie was set:

get '/' => sub {
  set_cookie('test' => 'test');
  set_cookie('test1' => 'test1');
...
}

wget -S http://172.20.124.111:3000/
--14:22:48--  http://172.20.124.111:3000/
           => `index.html'  
Connecting to 172.20.124.111:3000... connected.
HTTP request sent, awaiting response... 
  HTTP/1.0 200 OK
  Content-Type: text/html; charset=utf-8
  Set-Cookie: test1=test1; path=/; HttpOnly
  X-Powered-By: Perl Dancer 1.3011

The problem, as i can see, is in the Renderer.pm, function
response_with_headers.

With patch:
--- Renderer.pm 2011-02-22 14:03:43.000000000 +0200
+++ Renderer.pm.new     2011-02-22 13:57:38.000000000 +0200
@@ -55,12 +55,14 @@
     $response->header('X-Powered-By' => "Perl Dancer ${Dancer::VERSION}"); 
     # add cookies
+    my @c = ();
     foreach my $c (keys %{Dancer::Cookies->cookies}) {
         my $cookie = Dancer::Cookies->cookies->{$c};
         if (Dancer::Cookies->has_changed($cookie)) {
-            $response->header('Set-Cookie' => $cookie->to_header);
+            push(@c, $cookie->to_header);
         }
     }
+    $response->header('Set-Cookie' => \@c);
 
     return $response;
 }

i have normal headers generation:
wget -S http://172.20.124.111:3000/
--14:26:53--  http://172.20.124.111:3000/
           => `index.html'  
Connecting to 172.20.124.111:3000... connected.
HTTP request sent, awaiting response... 
  HTTP/1.0 200 OK
  Content-Type: text/html; charset=utf-8
  Set-Cookie: test=test; path=/; HttpOnly
  Set-Cookie: dancer.session=708630204583990864004761600357449618; path=/; HttpOnly Set-Cookie: test1=test1; path=/; HttpOnly
  X-Powered-By: Perl Dancer 1.3011


-- 
Close your eyes, look into the dream...

Jabber ID   : sapsan at gmail.com
E-mail      : sapsan at gmail.com


More information about the Dancer-users mailing list