<div dir="ltr">Hi all,<div><br></div><div>I would like to add an extra cookie to a request and redirect it. The code that I would think should work does not appear to be doing so, though.</div><div><br></div><div>Here's the route in question:</div><div><br></div><div><div>any '/login' => sub {</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">    </span>my $c = Dancer2::Core::Cookie->new(</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">         </span>name => 'return_to',</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">                </span>value => '/',</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">               </span>domain => config->{sso_domain},</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">          </span>expires => '5 mins'<br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>);</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">    </span>push_response_header 'Set-Cookie' => $c->to_header;</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">     </span>redirect '<a href="http://example.com">http://example.com</a>';<br></div></div><div>};</div><div><br></div><div><br></div><div>When I test this code, though, nothing shows up in the cookie jar:</div><div><br></div><div><div>my $res = $app->request( GET '/login' );</div><div><br></div><div>is( $res->code, 302, '[GET /login] Correct code' );<br></div><div><br></div><div>is(<br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">     </span>$res->headers->header('Location'),</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>'<a href="http://example.com">http://example.com</a>',</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>'Correct Location header',</div><div>);</div><div><br></div><div>$jar->extract_cookies( $res );</div><div>say 'cookies: ' . $jar->as_string; <br></div><div># output: "cookies: " -- i.e. no cookies found<br></div><div><br></div><div>say 'headers: ' . Dumper $res->headers;<br></div><div># output:<br></div></div>headers: bless( {<br>  "::std_case" => {<br>    cookie => "Cookie",<br>    "set-cookie" => "Set-Cookie",<br>    "set-cookie2" => "Set-Cookie2"<br>  },<br>  "content-length" => 303,<br>  "content-type" => "text/html; charset=utf-8",<br>  cookie => "return_to=%2F; path=/; expires=Thu, 04-Aug-2016 20:47:05 GMT; domain=<a href="http://example.com">example.com</a>",<br>  location => "<a href="http://example.com">http://example.com</a>"<br>}, 'HTTP::Headers' )<div><br></div><div>I'm not sure where the problem is -- am I setting the cookie incorrectly? Does it not get added to the redirected request?</div><div><br></div><div>Any suggestions gratefully received! Thanks.</div></div>