8000 bug #24878 [HttpFoundation] Prevent PHP from sending Last-Modified on… · symfony/symfony@8e9f976 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e9f976

Browse files
committed
bug #24878 [HttpFoundation] Prevent PHP from sending Last-Modified on session start (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [HttpFoundation] Prevent PHP from sending Last-Modified on session start | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #24849 | License | MIT | Doc PR | - I really don't know why PHP sends this Last-Modified header. Let's bypass that and throw headers ourselves instead. Commits ------- 2c0dc74 [HttpFoundation] Prevent PHP from sending Last-Modified on session start
2 parents bd0899e + 2c0dc74 commit 8e9f976

File tree

9 files changed

+11
-9
lines changed

9 files changed

+11
-9
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/AbstractSessionHandler.php

Lines changed: 3 additions & 0 deletions
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
}

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 1 addition & 1 deletion
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,

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/common.inc

Lines changed: 1 addition & 2 deletions
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";

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/empty_destroys.expected

Lines changed: 1 addition & 1 deletion
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

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/read_only.expected

Lines changed: 1 addition & 1 deletion
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

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/regenerate.expected

Lines changed: 1 addition & 1 deletion
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

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/storage.expected

Lines changed: 1 addition & 1 deletion
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

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/Fixtures/with_cookie.expected

Lines changed: 1 addition & 1 deletion
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

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 1 addition & 1 deletion
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()

0 commit comments

Comments
 (0)
0