Skip to content

Commit fc7da90

Browse files
committed
Fixing tests inconsistency and complet code
1 parent ddf09bf commit fc7da90

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Symfony/Component/HttpKernel/HttpCache/Store.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,16 @@ public function write(Request $request, Response $response): string
211211

212212
// read existing cache entries, remove non-varying, and add this one to the list
213213
$entries = [];
214-
$vary = $response->headers->all('vary');
215-
$vary = implode(', ', $vary);
216-
foreach ($this->getMetadata($key) as $entry) {
214+
$vary = implode(', ', $response->headers->all('vary'));
215+
foreach ($this->getMetadata($key) as $entry) {
217216
if (!isset($entry[1]['vary'][0])) {
218-
$entry[1]['vary'] = [''];
217+
$entry[1]['vary'] = [];
219218
}
220219

220+
// Get the previous vary change
221221
$olderVary = [];
222-
if (\count($entry[1]['vary']) > 1) {
223-
$olderVary = array_filter($entry[1]['vary'], fn ($entryVary) => str_contains($vary, $entryVary));
222+
if (\count($entry[1]['vary']) >= 1) {
223+
$olderVary = array_filter($entry[1]['vary'], fn ($entryVary) => str_contains($vary, $entryVary) === false);
224224
}
225225

226226
if (0 !== \count($olderVary) || !$this->requestsMatch($vary ?? '', $entry[0], $storedEnv)) {

src/Symfony/Component/HttpKernel/Tests/HttpCache/StoreTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,15 @@ public function testLoadsBodyEval()
351351

352352
public function testWriteWithMultipleVary()
353353
{
354-
$req1 = Request::create('/foo', 'get', [], [], [], ['HTTP_FOO' => 'bar']);
354+
$req1 = Request::create('/foo', 'get', [], [], [], ['HTTP_FOO' => 'foo','HTTP_BAR' => 'bar']);
355355
$content = str_repeat('a', 24).'b'.str_repeat('a', 24);
356356
$res1 = new Response($content, 200, ['vary' => ['Foo', 'Bar'], 'X-Body-Eval' => 'SSI']);
357357
$this->store->write($req1, $res1);
358358

359359
$responseLook = $this->store->lookup($req1);
360360
$this->assertSame($content, $responseLook->getContent());
361361

362-
$req2 = Request::create('/foo', 'get', [], [], [], ['HTTP_FOO' => 'foobar']);
362+
$req2 = Request::create('/foo', 'get', [], [], [], ['HTTP_FOO' => 'foo','HTTP_BAR' => 'foobar']);
363363
$content2 = str_repeat('b', 24).'a'.str_repeat('b', 24);
364364
$res2 = new Response($content2, 200, ['vary' => ['Foo', 'Bar'], 'X-Body-Eval' => 'SSI']);
365365
$this->store->write($req2, $res2);

0 commit comments

Comments
 (0)