Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

FIx for issue 301, adding support for max-age attribute to cookies #305

Merged
merged 2 commits into from

2 participants

@remorse

Hi! This should add the max-age attribute to cookies. I've also changed the test file to keep things in order.

@miyagawa miyagawa merged commit 41a6c51 into plack:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 29, 2012
  1. @remorse
  2. @remorse

    issue 301; fix documentation

    remorse authored
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 5 deletions.
  1. +3 −1 lib/Plack/Response.pm
  2. +6 −4 t/Plack-Response/cookie.t
View
4 lib/Plack/Response.pm
@@ -138,6 +138,7 @@ sub _bake_cookie {
push @cookie, "domain=" . $val->{domain} if $val->{domain};
push @cookie, "path=" . $val->{path} if $val->{path};
push @cookie, "expires=" . $self->_date($val->{expires}) if $val->{expires};
+ push @cookie, "max-age=" . $val->{"max-age"} if $val->{"max-age"};
push @cookie, "secure" if $val->{secure};
push @cookie, "HttpOnly" if $val->{httponly};
@@ -275,7 +276,8 @@ Returns a hash reference containing cookies to be set in the
response. The keys of the hash are the cookies' names, and their
corresponding values are a plain string (for C<value> with everything
else defaults) or a hash reference that can contain keys such as
-C<value>, C<domain>, C<expires>, C<path>, C<httponly>, C<secure>.
+C<value>, C<domain>, C<expires>, C<path>, C<httponly>, C<secure>,
+C<max-age>.
C<expires> can take a string or an integer (as an epoch time) and
B<does not> convert string formats such as C<+3M>.
View
10 t/Plack-Response/cookie.t
@@ -7,8 +7,9 @@ use HTTP::Request::Common;
my $app = sub {
my $res = Plack::Response->new(200);
- $res->cookies->{foo} = { value => "bar", domain => '.example.com', path => '/cgi-bin' };
- $res->cookies->{bar} = { value => "xxx yyy", expires => time + 3600 };
+ $res->cookies->{t1} = { value => "bar", domain => '.example.com', path => '/cgi-bin' };
+ $res->cookies->{t2} = { value => "xxx yyy", expires => time + 3600 };
+ $res->cookies->{t3} = { value => "123123", "max-age" => 15 };
$res->finalize;
};
@@ -17,8 +18,9 @@ test_psgi $app, sub {
my $res = $cb->(GET "/");
my @v = sort $res->header('Set-Cookie');
- like $v[0], qr/bar=xxx%20yyy; expires=\w+, \d+-\w+-\d+ \d\d:\d\d:\d\d GMT/;
- is $v[1], "foo=bar; domain=.example.com; path=/cgi-bin";
+ is $v[0], "t1=bar; domain=.example.com; path=/cgi-bin";
+ like $v[1], qr/t2=xxx%20yyy; expires=\w+, \d+-\w+-\d+ \d\d:\d\d:\d\d GMT/;
+ is $v[2], "t3=123123; max-age=15";
};
done_testing;
Something went wrong with that request. Please try again.