Dancer2 Cookie Expiry Question
Hi All, I've tried setting my own cookie with Dancer2 and also setting the session engine as Cookie. I'm using Windows 32 Bit (under Cygwin), with Perl 5.22 Dancer2::Session::Cookie - 0.006 Dancer2 - 0.0161000 Dancer2::Core::Cookie - 0.16000 Although I couldn't find a lot on the Dancer2 method, there is a bit on how to do this with Dancer1. I have this in my config.yml (thanks Andrew for the help with this): template: "template_toolkit" session: Cookie engines: template: template_toolkit: start_tag: '<%' end_tag: '%>' session: Cookie: secret_key: mykey default_duration: 60480064 However when the session is created, as per this image below, the session expiry is still 'session' instead of the time I set, which should be roughly. [image: Inline image 1] Any help would be appreciated, even if I could create another session and set the expiry or something but it all seems to point to something from config.yml not being set in the session. I've had a look at the cookie tests but I still can't figure out how to work with cookies properly in Dancer2. The date I set should set the session cookie to around 2130. I've also tried lower times with no effect. Thanks a lot, David
On Thu, 2015-08-20 at 09:08 +0930, David H wrote:
I've tried setting my own cookie with Dancer2 and also setting the session engine as Cookie. ... Although I couldn't find a lot on the Dancer2 method, there is a bit on how to do this with Dancer1.
I have this in my config.yml (thanks Andrew for the help with this): template: "template_toolkit" session: Cookie engines: template: template_toolkit: start_tag: '<%' end_tag: '%>' session: Cookie: secret_key: mykey default_duration: 60480064
However when the session is created, as per this image below, the session expiry is still 'session' instead of the time I set, which should be roughly.
I've not used Dancer2::Session::Cookie, but I know the following works for the YAML session engine. Therefore, it might be worth trying the generic cookie_duration parameter instead: engines: session: YAML: session_dir: "/tmp/dancer-sessions" cookie_duration: 3600
I've had a look at the cookie tests but I still can't figure out how to work with cookies properly in Dancer2. The date I set should set the session cookie to around 2130. I've also tried lower times with no effect.
To set a cookie: cookie MYCOOKIE => 'value', expires => '+2h', domain => $cookie_domain; (I guess the domain is optional - I've just copied that from existing code) To get a cookie: my $code = cookie 'MYCOOKIE' Regards, Andy
Thanks, it was something stupidly simple. No idea what the domain is either but I don't care as long as the thing sets and sets with a very very long expiry. cookie user => $thing, expires => '+2000h'; Did it. Thanks again, David On Thu, Aug 20, 2015 at 5:53 PM, Andrew Beverley <andy@andybev.com> wrote:
On Thu, 2015-08-20 at 09:08 +0930, David H wrote:
I've tried setting my own cookie with Dancer2 and also setting the session engine as Cookie. ... Although I couldn't find a lot on the Dancer2 method, there is a bit on how to do this with Dancer1.
I have this in my config.yml (thanks Andrew for the help with this): template: "template_toolkit" session: Cookie engines: template: template_toolkit: start_tag: '<%' end_tag: '%>' session: Cookie: secret_key: mykey default_duration: 60480064
However when the session is created, as per this image below, the session expiry is still 'session' instead of the time I set, which should be roughly.
I've not used Dancer2::Session::Cookie, but I know the following works for the YAML session engine. Therefore, it might be worth trying the generic cookie_duration parameter instead:
engines: session: YAML: session_dir: "/tmp/dancer-sessions" cookie_duration: 3600
I've had a look at the cookie tests but I still can't figure out how to work with cookies properly in Dancer2. The date I set should set the session cookie to around 2130. I've also tried lower times with no effect.
To set a cookie:
cookie MYCOOKIE => 'value', expires => '+2h', domain => $cookie_domain;
(I guess the domain is optional - I've just copied that from existing code)
To get a cookie:
my $code = cookie 'MYCOOKIE'
Regards,
Andy
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
On Thu, 2015-08-20 at 23:12 +0930, David H wrote:
I've had a look at the cookie tests but I still can't figure out how to work with cookies properly in Dancer2. The date I set should set the session cookie to around 2130. I've also tried lower times with no effect.
To set a cookie:
cookie MYCOOKIE => 'value', expires => '+2h', domain => $cookie_domain;
(I guess the domain is optional - I've just copied that from existing code)
To get a cookie:
my $code = cookie 'MYCOOKIE'
Thanks, it was something stupidly simple. No idea what the domain is either but I don't care as long as the thing sets and sets with a very very long expiry.
cookie user => $thing, expires => '+2000h';
For info, the various time formats for the expiry are here: https://metacpan.org/pod/Dancer2::Core::Time You can also do (for example) '+3M' Andy
participants (2)
-
Andrew Beverley -
David H