Permalink
Browse files

Merge branch 'review/chrisa_multiple_cookies' into devel

  • Loading branch information...
2 parents 8fa1898 + dc5c580 commit 86dc80d3c21245f0fc05a0967d85ccda5900ac64 @dams dams committed Feb 15, 2011
Showing with 45 additions and 2 deletions.
  1. +4 −0 CHANGES
  2. +7 −2 lib/Dancer/Renderer.pm
  3. +34 −0 t/12_response/07_cookies.t
View
@@ -1,5 +1,9 @@
{{$NEXT}}
+ [ BUG FIXES ]
+ * Fix cookies disappearing when more than one is set.
+ (Chris Andrews)
+
[ ENHANCEMENTS ]
* Add Dancer::Logger::Null.
(Sawyer X)
@@ -55,13 +55,18 @@ sub response_with_headers {
$response->header('X-Powered-By' => "Perl Dancer ${Dancer::VERSION}");
# add cookies
+ my @cookies = ();
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 @cookies, $cookie->to_header;
}
}
-
+ if (scalar @cookies) {
+ my $header = join ', ', @cookies;
+ $response->header('Set-Cookie' => $header);
+ }
+
return $response;
}
@@ -0,0 +1,34 @@
+use strict;
+use warnings;
+
+use Test::More import => ['!pass'];
+use File::Spec;
+use lib File::Spec->catdir( 't', 'lib' );
+use TestUtils;
+
+use Dancer ':syntax';
+
+get '/onecookie', sub {
+ set_cookie 'A'=> "thevalueofA";
+ return '';
+};
+
+get '/twocookies', sub {
+ set_cookie 'A'=> "thevalueofA";
+ set_cookie 'B'=> "thevalueofB";
+ return '';
+};
+
+plan tests => 2;
+
+# /onecookie
+my $req = fake_request(GET => '/onecookie');
+Dancer::SharedData->request($req);
+my $headers = Dancer::Renderer::render_action();
+is($headers->header('Set-Cookie'), 'A=thevalueofA; path=/; HttpOnly');
+
+# /twocookies
+$req = fake_request(GET => '/twocookies');
+Dancer::SharedData->request($req);
+$headers = Dancer::Renderer::render_action();
+is($headers->header('Set-Cookie'), 'A=thevalueofA; path=/; HttpOnly, B=thevalueofB; path=/; HttpOnly');

0 comments on commit 86dc80d

Please sign in to comment.