Permalink
Browse files

bug #27714 [HttpFoundation] fix session tracking counter (nicolas-gre…

…kas, dmaicher)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpFoundation] fix session tracking counter

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

As just discussed with @nicolas-grekas I found this issue today while upgrading my app to 3.4.12. Somehow its not possible anymore to set caching headers correctly since this commit: 146e01c#diff-5350dc763df30ada9d00563c115f6652

Commits
-------

89ed756 failing test to reproduce session problem
26fc4e6 [HttpFoundation] fix session tracking counter
  • Loading branch information...
nicolas-grekas committed Jun 28, 2018
2 parents ad066bb + 89ed756 commit b9a3c870d91c9512c939cff704b910b7b9ff163e
@@ -43,6 +43,14 @@ public function welcomeAction(Request $request, $name = null)
return new Response(sprintf('Welcome back %s, nice to meet you.', $name));
}
public function cacheableAction()
{
$response = new Response('all good');
$response->setSharedMaxAge(100);
return $response;
}
public function logoutAction(Request $request)
{
$request->getSession()->invalidate();
@@ -2,6 +2,10 @@ session_welcome:
path: /session
defaults: { _controller: TestBundle:Session:welcome }
session_cacheable:
path: /cacheable
defaults: { _controller: Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::cacheableAction }
session_welcome_name:
path: /session/{name}
defaults: { _controller: TestBundle:Session:welcome }
@@ -126,6 +126,22 @@ public function testTwoClients($config, $insulate)
$this->assertContains('Welcome back client2, nice to meet you.', $crawler2->text());
}
/**
* @dataProvider getConfigs
*/
public function testCorrectCacheControlHeadersForCacheableAction($config, $insulate)
{
$client = $this->createClient(array('test_case' => 'Session', 'root_config' => $config));
if ($insulate) {
$client->insulate();
}
$client->request('GET', '/cacheable');
$response = $client->getResponse();
$this->assertSame('public, s-maxage=100', $response->headers->get('cache-control'));
}
public function getConfigs()
{
return array(
@@ -54,8 +54,6 @@ public function __construct(SessionStorageInterface $storage = null, AttributeBa
*/
public function start()
{
++$this->usageIndex;
return $this->storage->start();
}
@@ -160,7 +158,9 @@ public function getUsageIndex()
*/
public function isEmpty()
{
++$this->usageIndex;
if ($this->isStarted()) {
++$this->usageIndex;
}
foreach ($this->data as &$data) {
if (!empty($data)) {
return false;
@@ -185,8 +185,6 @@ public function invalidate($lifetime = null)
*/
public function migrate($destroy = false, $lifetime = null)
{
++$this->usageIndex;
return $this->storage->regenerate($destroy, $lifetime);
}
@@ -195,8 +193,6 @@ public function migrate($destroy = false, $lifetime = null)
*/
public function save()
{
++$this->usageIndex;
$this->storage->save();
}
@@ -44,6 +44,9 @@ public function getBag()
*/
public function isEmpty()
{
if (!isset($this->data[$this->bag->getStorageKey()])) {
return true;
}
++$this->usageIndex;
return empty($this->data[$this->bag->getStorageKey()]);
@@ -81,8 +84,6 @@ public function getStorageKey()
*/
public function clear()
{
++$this->usageIndex;
return $this->bag->clear();
}
}

0 comments on commit b9a3c87

Please sign in to comment.