[Catalyst] Make Catalyst NOT reset a cookie on a per action basis

Steve Kleiman steve at prodhub.com
Tue Aug 18 00:19:17 GMT 2009


Thanks for taking a look. I thought I had it isolated but seems not.  
Tried what you suggested below but the instigator of the cookie  
happens at a different juncture.

The instigator for a 'Catalyst::Plugin::Session' cookie being set is  
'Session::prepare_action'. The method calls 'sessionid' which  
ultimately invokes the resetting of the cookie.

> sub prepare_action {
>     my $c = shift;
>
>     if (    $c->config->{session}{flash_to_stash}
>         and $c->sessionid
>         and my $flash_data = $c->flash )
>     {
>         @{ $c->stash }{ keys %$flash_data } = values %$flash_data;
>     }
>
>     $c->maybe::next::method(@_);
> }

So a more refined question would be, is there a way to wrap only  
'Session::prepare_action' whilst not wrapping all the other  
'prepare_action' methods? I've tried the following but have had no luck:
> before 'prepare_action' => sub { ... }
> before 'Session::prepare_action' => sub { ... }
> before 'Catalyst::Plugin::Session::prepare_action' => sub { ... }

Thanks for the help....

-steve



On Aug 17, 2009, at 2:33 PM, Tomas Doran wrote:

>
> On 16 Aug 2009, at 19:59, Steve Kleiman wrote:
>> WHAT I CAN SEE:
>> Catalyst engine calls "finalize_cookies" which resets every cookie  
>> it finds. This takes place before the 'begin' method and the 'Set- 
>> Cookie' header has already been dispatched. Therefore removing that  
>> header in 'begin' does nothing. If the original request did not  
>> present a cookie, then Catalyst does not regurgitate the cookie and  
>> everything works great.
>>
>> Thanks for any guidance. It'd be great of there's a solution that  
>> doesn't require constraining the cookie path.
>
> How about:
>
> after 'finalize_cookies' => sub {
>    my $c = shift;
>    $c->res->cookies({}) if $c->stash->{no_cookies};
> };
>
> in your MyApp.pm, then just arrange for things to set $c->stash- 
> >{no_cookies}?
>
> Cheers
> t0m




More information about the Catalyst mailing list