8000 feature #60569 [HttpKernel] Do not superseed private cache-control wh… · symfony/symfony@8c89e4c · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c89e4c

Browse files
committed
feature #60569 [HttpKernel] Do not superseed private cache-control when no-store is set (alexander-schranz)
This PR was submitted for the 7.3 branch but it was squashed and merged into the 7.4 branch instead. Discussion ---------- [HttpKernel] Do not superseed private cache-control when no-store is set | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT I don't think its a good idea to superseed the private cache control via the new noStore option * #59301 If somebody want to set it to `private` they should explicit do it. via `#[Cache(private: true, noStore: true)]`. I would avoid this non transparent changes in general. I had usecases in the past where the response is still public for the symfony cache and varnish public and the no store was only for the third party caches and in browser caches. This specially come into play with usage of `ESI` where the general page is cached, but no-store set to not allow back forwards caches, because of the ESI content. /cc `@smnandre` Commits ------- 7e6e33e [HttpKernel] Do not superseed private cache-control when no-store is set
2 parents e9f91a6 + 7e6e33e commit 8c89e4c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/Symfony/Component/HttpKernel/EventListener/CacheAttributeListener.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ public function onKernelResponse(ResponseEvent $event): void
165165
}
166166

167167
if (true === $cache->noStore) {
168-
$response->setPrivate();
169168
$response->headers->addCacheControlDirective('no-store');
170169
}
171170

src/Symfony/Component/HttpKernel/Tests/EventListener/CacheAttributeListenerTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ public function testResponseIsPublicIfConfigurationIsPublicTrueNoStoreFalse()
102102
$this->assertFalse($this->response->headers->hasCacheControlDirective('no-store'));
103103
}
104104

105-
public function testResponseIsPrivateIfConfigurationIsPublicTrueNoStoreTrue()
105+
public function testResponseKeepPublicIfConfigurationIsPublicTrueNoStoreTrue()
106106
{
107107
$request = $this->createRequest(new Cache(public: true, noStore: true));
108108

109109
$this->listener->onKernelResponse($this->createEventMock($request, $this->response));
110110

111-
$this->assertFalse($this->response->headers->hasCacheControlDirective('public'));
112-
$this->assertTrue($this->response->headers->hasCacheControlDirective('private'));
111+
$this->assertTrue($this->response->headers->hasCacheControlDirective('public'));
112+
$this->assertFalse($this->response->headers->hasCacheControlDirective('private'));
113113
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-store'));
114114
}
115115

116-
public function testResponseIsPrivateNoStoreIfConfigurationIsNoStoreTrue()
116+
public function testResponseKeepPrivateNoStoreIfConfigurationIsNoStoreTrue()
117117
{
118118
$request = $this->createRequest(new Cache(noStore: true));
119119

@@ -124,14 +124,14 @@ public function testResponseIsPrivateNoStoreIfConfigurationIsNoStoreTrue()
124124
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-store'));
125125
}
126126

127-
public function testResponseIsPrivateIfSharedMaxAgeSetAndNoStoreIsTrue()
127+
public function testResponseIsPublicIfSharedMaxAgeSetAndNoStoreIsTrue()
128128
{
129129
$request = $this->createRequest(new Cache(smaxage: 1, noStore: true));
130130

131131
$this->listener->onKernelResponse($this->createEventMock($request, $this->response));
132132

133-
$this->assertFalse($this->response->headers->hasCacheControlDirective('public'));
134-
$this->assertTrue($this->response->headers->hasCacheControlDirective('private'));
133+
$this->assertTrue($this->response->headers->hasCacheControlDirective('public'));
134+
$this->assertFalse($this->response->headers->hasCacheControlDirective('private'));
135135
$this->assertTrue($this->response->headers->hasCacheControlDirective('no-store'));
136136
}
137137

0 commit comments

Comments
 (0)
0