8000 [HttpFoundation] Prevent PHP from sending Last-Modified on session start by nicolas-grekas · Pull Request #24878 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[HttpFoundation] Prevent PHP from sending Last-Modified on session start
  • Loading branch information
nicolas-grekas committed Nov 9, 2017
commit 2c0dc745d63bfe227db07d4bb74adc47d585d950
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we raise a warning or something in !ini_get('session.cache_limiter') && headers_sent() ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure, there are many similar checks in the code base already

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this one convinced me... 😅

header(sprintf('Cache-Control: max-age=%d, private, must-revalidate', 60 * (int) ini_get('session.cache_expire')));
}

return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function __construct(array $options = array(), $handler = null, MetadataB
}

$options += array(
'cache_limiter' => 'private_no_expire',
'cache_limiter' => '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the phpdoc with the standard options is wrong now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in cf4eb46

'cache_expire' => 0,
'use_cookies' => 1,
'lazy_write' => 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function testDefaultSessionCacheLimiter()
$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()
Expand Down
0