From: Hu Hailin Date: Sun, 6 Aug 2006 12:10:37 +0000 (+0000) Subject: add configuration of 'cookie_path' X-Git-Tag: v0.05~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Plugin-Session-State-Cookie.git;a=commitdiff_plain;h=8bdcbb468aedff34275a7fb30b18ea8be066255b;hp=431c1b4bc991f19500eaf6314a4a68bba10e5762 add configuration of 'cookie_path' --- diff --git a/Changes b/Changes index 8b4b8f8..75df1c6 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ Revision history for Perl extension Catalyst::Plugin::Session::State::Cookie +0.05 2006-08-06 20:50:00 + - Add configuration of 'cookie_path' (Michael W Peterson) + 0.04 - Depend on a higher version of C::P::Session diff --git a/lib/Catalyst/Plugin/Session/State/Cookie.pm b/lib/Catalyst/Plugin/Session/State/Cookie.pm index 7fbde70..a87ccc8 100644 --- a/lib/Catalyst/Plugin/Session/State/Cookie.pm +++ b/lib/Catalyst/Plugin/Session/State/Cookie.pm @@ -7,7 +7,7 @@ use warnings; use NEXT; use Catalyst::Utils (); -our $VERSION = "0.04"; +our $VERSION = "0.05"; sub setup_session { my $c = shift; @@ -38,8 +38,21 @@ sub set_session_id { sub update_session_cookie { my ( $c, $updated ) = @_; - my $cookie_name = $c->config->{session}{cookie_name}; - $c->response->cookies->{$cookie_name} = $updated; + + unless ( $c->cookie_is_rejecting( $updated ) ) { + my $cookie_name = $c->config->{session}{cookie_name}; + $c->response->cookies->{$cookie_name} = $updated; + } +} + +sub cookie_is_rejecting { + my ( $c, $cookie ) = @_; + + if ( $cookie->{path} ) { + return 1 if index $c->request->path, $cookie->{path}; + } + + return 0; } sub make_session_cookie { @@ -49,6 +62,7 @@ sub make_session_cookie { my $cookie = { value => $sid, ( $cfg->{cookie_domain} ? ( domain => $cfg->{cookie_domain} ) : () ), + ( $cfg->{cookie_path} ? ( path => $cfg->{cookie_path} ) : () ), %attrs, }; @@ -190,6 +204,10 @@ user's browser is shut down. If this attribute set true, the cookie will only be sent via HTTPS. +=item cookie_path + +The path of the request url where cookie should be baked. + =back =head1 CAVEATS diff --git a/t/basic.t b/t/basic.t index 9620451..843ff26 100644 --- a/t/basic.t +++ b/t/basic.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 10; +use Test::More tests => 13; use Test::MockObject; use Test::MockObject::Extends; @@ -71,3 +71,14 @@ is_deeply( { session => { value => $sessionid, expires => 123 } }, "cookie was set correctly" ); + +$cxt->clear; +$req->clear; + +can_ok( $m, "cookie_is_rejecting" ); + +%req_cookies = ( path => '/foo' ); +$req->set_always( path => '/' ); +ok( $cxt->cookie_is_rejecting(\%req_cookies), "cookie is rejecting" ); +$req->set_always( path => '/foo/bar' ); +ok( !$cxt->cookie_is_rejecting(\%req_cookies), "cookie is not rejecting" );