8000 [HttpFoundation] Prevent PHP from sending Last-Modified on session start · symfony/symfony@2c0dc74 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c0dc74

Browse files
[HttpFoundation] Prevent PHP from sending Last-Modified on session start
1 parent 8cd2193 commit 2c0dc74

Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ abstract class AbstractSessionHandler implements \SessionHandlerInterface, \Sess
3232
public function open($savePath, $sessionName)
3333
{
3434
$this->sessionName = $sessionName;
35+
if (!headers_sent() && !ini_get('session.cache_limiter')) {
36+
header(sprintf('Cache-Control: max-age=%d, private, must-revalidate', 60 * (int) ini_get('session.cache_expire')));
37+
}
3538

3639
return true;
3740
}
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB
107107
}
108108

109109
$options += array(
110-
'cache_limiter' => 'private_no_expire',
110+
'cache_limiter' => '',
111111
'cache_expire' => 0,
112112
'use_cookies' => 1,
113113
'lazy_write' => 1,
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ ini_set('session.use_strict_mode', 1);
3838
ini_set('session.lazy_write', 1);
3939
ini_set('session.name', 'sid');
4040
ini_set('session.save_path', __DIR__);
41-
ini_set('session.cache_limiter', 'private_no_expire');
41+
ini_set('session.cache_limiter', '');
4242

4343
header_remove('X-Powered-By');
4444
header('Content-Type: text/plain; charset=utf-8');
4545

4646
register_shutdown_function(function () {
4747
echo "\n";
48-
header_remove('Last-Modified');
4948
session_write_close();
5049
print_r(headers_list());
5150
echo "shutdown\n";
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ close
1111
Array
1212
(
1313
[0] => Content-Type: text/plain; charset=utf-8
14-
[1] => Cache-Control: private, max-age=10800
14+
[1] => Cache-Control: max-age=10800, private, must-revalidate
1515
[2] => Set-Cookie: sid=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; secure; HttpOnly
1616
)
1717
shutdown
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ close
99
Array
1010
(
1111
[0] => Content-Type: text/plain; charset=utf-8
12-
[1] => Cache-Control: private, max-age=10800
12+
[1] => Cache-Control: max-age=10800, private, must-revalidate
1313
)
1414
shutdown
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ close
1818
Array
1919
(
2020
[0] => Content-Type: text/plain; charset=utf-8
21-
[1] => Cache-Control: private, max-age=10800
21+
[1] => Cache-Control: max-age=10800, private, must-revalidate
2222
[2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly
2323
)
2424
shutdown
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ $_SESSION is not empty
1515
Array
1616
(
1717
[0] => Content-Type: text/plain; charset=utf-8
18-
[1] => Cache-Control: private, max-age=0
18+
[1] => Cache-Control: max-age=0, private, must-revalidate
1919
)
2020
shutdown
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ close
99
Array
1010
(
1111
[0] => Content-Type: text/plain; charset=utf-8
12-
[1] => Cache-Control: private, max-age=10800
12+
[1] => Cache-Control: max-age=10800, private, must-revalidate
1313
[2] => Set-Cookie: abc=def
1414
)
1515
shutdown
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function testDefaultSessionCacheLimiter()
150150
$this->iniSet('session.cache_limiter', 'nocache');
151151

152152
$storage = new NativeSessionStorage();
153-
$this->assertEquals('private_no_expire', ini_get('session.cache_limiter'));
153+
$this->assertEquals('', ini_get('session.cache_limiter'));
154154
}
155155

156156
public function testExplicitSessionCacheLimiter()