Skip to content

Commit

Permalink
Make the session cacheLimiter a configuration option.
Browse files Browse the repository at this point in the history
Instead of hardcoding to must-revalidate, developers can use a more
suitable option if they do not have to support IE8.

Refs #7096
  • Loading branch information
markstory committed Jan 19, 2016
1 parent a530414 commit 57f620f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/Config/core.php
Expand Up @@ -201,6 +201,8 @@
* to the ini array.
* - `Session.autoRegenerate` - Enabling this setting, turns on automatic renewal of sessions, and
* sessionids that change frequently. See CakeSession::$requestCountdown.
* - `Session.cacheLimiter` - Configure the cache control headers used for the session cookie.
* See http://php.net/session_cache_limiter for accepted values.
* - `Session.ini` - An associative array of additional ini values to set.
*
* The built in defaults are:
Expand Down
10 changes: 8 additions & 2 deletions lib/Cake/Model/Datasource/CakeSession.php
Expand Up @@ -541,6 +541,10 @@ protected static function _configureSession() {
if (!isset($sessionConfig['ini']['session.cookie_httponly'])) {
$sessionConfig['ini']['session.cookie_httponly'] = 1;
}
// For IE<=8
if (!isset($sessionConfig['cacheLimiter'])) {
$sessionConfig['cacheLimiter'] = 'must-revalidate';
}

if (empty($_SESSION)) {
if (!empty($sessionConfig['ini']) && is_array($sessionConfig['ini'])) {
Expand Down Expand Up @@ -696,8 +700,10 @@ protected static function _startSession() {
$_SESSION = array();
}
} else {
// For IE<=8
session_cache_limiter("must-revalidate");
$limit = Configure::read('Session.cacheLimiter');
if (!empty($limit)) {
session_cache_limiter($limit);
}
session_start();
}
return true;
Expand Down
16 changes: 16 additions & 0 deletions lib/Cake/Test/Case/Model/Datasource/CakeSessionTest.php
Expand Up @@ -514,6 +514,22 @@ public function testReadingSavedEmpty() {
$this->assertEquals(null, TestCakeSession::read('SessionTestCase'));
}

/**
* Test te cacheLimiter settings.
*
* @return void
*/
public function testCacheLimiter() {
Configure::write('Session.cacheLimiter', 'public');
TestCakeSession::start();
$this->assertSame('public', session_cache_limiter());

Configure::write('Session.cacheLimiter', 'private');
TestCakeSession::destroy();
TestCakeSession::start();
$this->assertSame('private', session_cache_limiter());
}

/**
* testCheckUserAgentFalse method
*
Expand Down

0 comments on commit 57f620f

Please sign in to comment.