8000 feature #47094 [HttpKernel] Use xxh128 algorithm instead of sha256 fo… · symfony/symfony@0b328d0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b328d0

Browse files
committed
feature #47094 [HttpKernel] Use xxh128 algorithm instead of sha256 for http cache store key (Pascal Woerde)
This PR was squashed before being merged into the 6.2 branch. Discussion ---------- [HttpKernel] Use xxh128 algorithm instead of sha256 for http cache store key | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #46893 | License | MIT Use xxh3 algorithm instead of sha256 for http cache store key. PR as requested in #46893 * Note that the xxHash support is available since PHP 8.1 as noted in the [change log](https://www.php.net/ChangeLog-8.php#PHP_8_1). Commits ------- 0acc3ea [HttpKernel] Use xxh128 algorithm instead of sha256 for http cache store key
2 parents fc868f4 + 0acc3ea commit 0b328d0

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/Symfony/Component/HttpFoundation/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.2
5+
---
6+
7+
* The HTTP cache store uses the `xxh128` algorithm
8+
49
6.1
510
---
611

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public function write(Request $request, Response $response): string
226226
*/
227227
protected function generateContentDigest(Response $response): string
228228
{
229-
return 'en'.hash('sha256', $response->getContent());
229+
return 'en'.hash('xxh128', $response->getContent());
230230
}
231231

232232
/**

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testSetsTheXContentDigestResponseHeaderBeforeStoring()
9494
$entries = $this->getStoreMetadata($cacheKey);
9595
[, $res] = $entries[0];
9696

97-
$this->assertEquals('en9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', $res['x-content-digest'][0]);
97+
$this->assertEquals('en6c78e0e3bd51d358d01e758642b85fb8', $res['x-content-digest'][0]);
9898
}
9999

100100
public function testDoesNotTrustXContentDigestFromUpstream()
@@ -105,8 +105,8 @@ public function testDoesNotTrustXContentDigestFromUpstream()
105105
$entries = $this->getStoreMetadata($cacheKey);
106106
[, $res] = $entries[0];
107107

108-
$this->assertEquals('en9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', $res['x-content-digest'][0]);
109-
$this->assertEquals('en9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', $response->headers->get('X-Content-Digest'));
108+
$this->assertEquals('en6c78e0e3bd51d358d01e758642b85fb8', $res['x-content-digest'][0]);
109+
$this->assertEquals('en6c78e0e3bd51d358d01e758642b85fb8', $response->headers->get('X-Content-Digest'));
110110
}
111111

112112
public function testWritesResponseEvenIfXContentDigestIsPresent()
@@ -198,7 +198,7 @@ public function testRestoresResponseContentFromEntityStoreWithLookup()
198198
{
199199
$this->storeSimpleEntry();
200200
$response = $this->store->lookup($this->request);
201-
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test')), $response->getContent());
201+
$this->assertEquals($this->getStorePath('en'.hash('xxh128', 'test')), $response->getContent());
202202
}
203203

204204
public function testInvalidatesMetaAndEntityStoreEntriesWithInvalidate()
@@ -251,9 +251,9 @@ public function testStoresMultipleResponsesForEachVaryCombination()
251251
$res3 = new Response('test 3', 200, ['Vary' => 'Foo Bar']);
252252
$this->store->write($req3, $res3);
253253

254-
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 3')), $this->store->lookup($req3)->getContent());
255-
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 2')), $this->store->lookup($req2)->getContent());
256-
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 1')), $this->store->lookup($req1)->getContent());
254+
$this->assertEquals($this->getStorePath('en'.hash('xxh128', 'test 3')), $this->store->lookup($req3)->getContent());
255+
$this->assertEquals($this->getStorePath('en'.hash('xxh128', 'test 2')), $this->store->lookup($req2)->getContent());
256+
$this->assertEquals($this->getStorePath('en'.hash('xxh128', 'test 1')), $this->store->lookup($req1)->getContent());
257257

258258
$this->assertCount(3, $this->getStoreMetadata($key));
259259
}
@@ -263,17 +263,17 @@ public function testOverwritesNonVaryingResponseWithStore()
263263
$req1 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
264264
$res1 = new Response('test 1', 200, ['Vary' => 'Foo Bar']);
265265
$this->store->write($req1, $res1);
266-
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 1')), $this->store->lookup($req1)->getContent());
266+
$this->assertEquals($this->getStorePath('en'.hash('xxh128', 'test 1')), $this->store->lookup($req1)->getContent());
267267

268268
$req2 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam']);
269269
$res2 = new Response('test 2', 200, ['Vary' => 'Foo Bar']);
270270
$this->store->write($req2, $res2);
271-
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 2')), $this->store->lookup($req2)->getContent());
271+
$this->assertEquals($this->getStorePath('en'.hash('xxh128', 'test 2')), $this->store->lookup($req2)->getContent());
272272

273273
$req3 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
274274
$res3 = new Response('test 3', 200, ['Vary' => 'Foo Bar']);
275275
$key = $this->store->write($req3, $res3);
276-
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 3')), $this->store->lookup($req3)->getContent());
276+
$this->assertEquals($this->getStorePath('en'.hash('xxh128', 'test 3')), $this->store->lookup($req3)->getContent());
277277

278278
$this->assertCount(2, $this->getStoreMetadata($key));
279279
}

0 commit comments

Comments
 (0)
0