Permalink
Browse files

expiresなしのsession Cookieを発行できるように

  • Loading branch information...
1 parent 5f8df83 commit 4f491b9dd7267c14900c8f36a1cb33da1dd15d19 @fujiwara fujiwara committed Sep 7, 2011
Showing with 55 additions and 12 deletions.
  1. +5 −4 lib/Ark/Plugin/Session/State/Cookie.pm
  2. +11 −8 lib/Ark/Response.pm
  3. +1 −0 t/plugin_session.t
  4. +38 −0 t/plugin_session_expire.t
View
9 lib/Ark/Plugin/Session/State/Cookie.pm
@@ -34,13 +34,14 @@ has cookie_path => (
has cookie_expires => (
is => 'rw',
- isa => 'Str',
lazy => 1,
default => sub {
my $self = shift;
- $self->class_config->{cookie_expires}
- || $self->app->config->{'Plugin::Session'}->{expires}
- || '+1d'; # 1day
+ exists $self->class_config->{cookie_expires}
+ ? $self->class_config->{cookie_expires}
+ : exists $self->app->config->{'Plugin::Session'}->{expires}
+ ? $self->app->config->{'Plugin::Session'}->{expires}
+ : '+1d'; # 1day
},
);
View
19 lib/Ark/Response.pm
@@ -159,14 +159,17 @@ sub _finalize_cookies {
my $cookie = (
Scalar::Util::blessed($val)
? $val
- : CGI::Simple::Cookie->new(
- -name => $name,
- -value => $val->{value},
- -expires => $val->{expires},
- -domain => $val->{domain},
- -path => $val->{path},
- -secure => ( $val->{secure} || 0 )
- )
+ : do {
+ my %args = (
+ -name => $name,
+ -value => $val->{value},
+ -domain => $val->{domain},
+ -path => $val->{path},
+ -secure => ( $val->{secure} || 0 )
+ );
+ $args{"-expires"} = $val->{expires} if defined $val->{expires};
+ CGI::Simple::Cookie->new(%args);
+ }
);
$self->headers->push_header( 'Set-Cookie' => $cookie->as_string );
View
1 t/plugin_session.t
@@ -70,6 +70,7 @@ use Ark::Test 'TestApp',
{
my $res = request(GET => '/test_set');
like( $res->header('Set-Cookie'), qr/testapp_session=/, 'session id ok');
+ like( $res->header('Set-Cookie'), qr/expires=./, 'session expire ok');
is(get('/test_get'), 'dummy', 'session get ok');
}
View
38 t/plugin_session_expire.t
@@ -0,0 +1,38 @@
+use Test::Base;
+
+{
+ package TestApp;
+ use Ark;
+
+ use_plugins qw/
+ Session
+ Session::State::Cookie
+ Session::Store::Memory
+ /;
+
+ conf 'Plugin::Session::State::Cookie' => {
+ cookie_expires => undef,
+ };
+
+ package TestApp::Controller::Root;
+ use Ark 'Controller';
+
+ has '+namespace' => default => '';
+
+ sub test_set :Local {
+ my ($self, $c) = @_;
+ $c->session->set('test', 'dummy');
+ }
+}
+
+plan 'no_plan';
+
+use Ark::Test 'TestApp',
+ components => [qw/Controller::Root/],
+ reuse_connection => 1;
+
+{
+ my $res = request(GET => '/test_set');
+ like( $res->header('Set-Cookie'), qr/testapp_session=/, 'session id ok');
+ unlike( $res->header('Set-Cookie'), qr/expires=/, 'session expires ok');
+}

0 comments on commit 4f491b9

Please sign in to comment.