Move call to _save_session_expires to finalize_session
Stefan Seifert [Thu, 30 Jun 2011 13:24:10 +0000 (13:24 +0000)]
_save_session_expires got called in finalize_header, because it
implicitly also extends the session expiry which in turn influences a
possible session cookie which has to be finalized before finalizing
headers.

This patch moves the call to _save_session_expires to finalize_session
with the rest of the _save_* calls and only leaves updating the
session_expiry in finalize_header. This is needed as base for a patch to
Catalyst::Plugin::SubRequest which will allow starting new sessions from
within a subrequest.

lib/Catalyst/Plugin/Session.pm

index cf7522a..f7aed87 100644 (file)
@@ -102,8 +102,10 @@ sub prepare_action {
 sub finalize_headers {
     my $c = shift;
 
-    # fix cookie before we send headers
-    $c->_save_session_expires;
+    # Force extension of session_expires before finalizing headers, so a possible cookie will be
+    # up to date. First call to session_expires will extend the expiry, subsequent calls will
+    # just return the previously extended value.
+    $c->session_expires;
 
     return $c->maybe::next::method(@_);
 }
@@ -124,6 +126,7 @@ sub finalize_session {
 
     $c->maybe::next::method(@_);
 
+    $c->_save_session_expires;
     $c->_save_session_id;
     $c->_save_session;
     $c->_save_flash;