[HttpFoundation] Prevent PHP from sending Last-Modified on session start

This commit is contained in:
Nicolas Grekas 2017-11-09 11:49:37 +01:00
parent 8cd2193a82
commit 2c0dc745d6
9 changed files with 11 additions and 9 deletions

View File

@ -32,6 +32,9 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
public function open($savePath, $sessionName)
{
$this->sessionName = $sessionName;
if (!headers_sent() && !ini_get('session.cache_limiter')) {
header(sprintf('Cache-Control: max-age=%d, private, must-revalidate', 60 * (int) ini_get('session.cache_expire')));
}
return true;
}

View File

@ -107,7 +107,7 @@ class NativeSessionStorage implements SessionStorageInterface
}
$options += array(
'cache_limiter' => 'private_no_expire',
'cache_limiter' => '',
'cache_expire' => 0,
'use_cookies' => 1,
'lazy_write' => 1,

View File

@ -38,14 +38,13 @@ ini_set('session.use_strict_mode', 1);
ini_set('session.lazy_write', 1);
ini_set('session.name', 'sid');
ini_set('session.save_path', __DIR__);
ini_set('session.cache_limiter', 'private_no_expire');
ini_set('session.cache_limiter', '');
header_remove('X-Powered-By');
header('Content-Type: text/plain; charset=utf-8');
register_shutdown_function(function () {
echo "\n";
header_remove('Last-Modified');
session_write_close();
print_r(headers_list());
echo "shutdown\n";

View File

@ -11,7 +11,7 @@ close
Array
(
[0] => Content-Type: text/plain; charset=utf-8
[1] => Cache-Control: private, max-age=10800
[1] => Cache-Control: max-age=10800, private, must-revalidate
[2] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
)
shutdown

View File

@ -9,6 +9,6 @@ close
Array
(
[0] => Content-Type: text/plain; charset=utf-8
[1] => Cache-Control: private, max-age=10800
[1] => Cache-Control: max-age=10800, private, must-revalidate
)
shutdown

View File

@ -18,7 +18,7 @@ close
Array
(
[0] => Content-Type: text/plain; charset=utf-8
[1] => Cache-Control: private, max-age=10800
[1] => Cache-Control: max-age=10800, private, must-revalidate
[2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly
)
shutdown

View File

@ -15,6 +15,6 @@ $_SESSION is not empty
Array
(
[0] => Content-Type: text/plain; charset=utf-8
[1] => Cache-Control: private, max-age=0
[1] => Cache-Control: max-age=0, private, must-revalidate
)
shutdown

View File

@ -9,7 +9,7 @@ close
Array
(
[0] => Content-Type: text/plain; charset=utf-8
[1] => Cache-Control: private, max-age=10800
[1] => Cache-Control: max-age=10800, private, must-revalidate
[2] => Set-Cookie: abc=def
)
shutdown

View File

@ -150,7 +150,7 @@ class NativeSessionStorageTest extends TestCase
$this->iniSet('session.cache_limiter', 'nocache');
$storage = new NativeSessionStorage();
$this->assertEquals('private_no_expire', ini_get('session.cache_limiter'));
$this->assertEquals('', ini_get('session.cache_limiter'));
}
public function testExplicitSessionCacheLimiter()