Skip to content

Commit 5364b76

Browse files
committed
Merge branch 'hotfix/2.2.2'
2 parents 6a59552 + 4cb5b3d commit 5364b76

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Psr6Store.php

+5
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class Psr6Store implements Psr6StoreInterface, ClearableInterface
4646
{
4747
const NON_VARYING_KEY = 'non-varying';
4848
const COUNTER_KEY = 'write-operations-counter';
49+
const CACHE_DEBUG_HEADER = 'toflar-psr6cache-requested-uri';
4950

5051
/**
5152
* @var array
@@ -221,6 +222,7 @@ public function write(Request $request, Response $response)
221222
}
222223

223224
$response->headers->set('X-Content-Digest', $contentDigest);
225+
$response->headers->set(self::CACHE_DEBUG_HEADER, $request->getUri());
224226

225227
if (!$response->headers->has('Transfer-Encoding')) {
226228
$response->headers->set('Content-Length', \strlen($response->getContent()));
@@ -564,6 +566,9 @@ private function saveDeferred($key, $data, $expiresAfter = null, $tags = [])
564566
*/
565567
private function restoreResponse(array $cacheData)
566568
{
569+
// Unset internal debug info
570+
unset($cacheData['headers'][self::CACHE_DEBUG_HEADER]);
571+
567572
if (isset($cacheData['headers']['x-content-digest'][0])) {
568573
$item = $this->cache->getItem($cacheData['headers']['x-content-digest'][0]);
569574
if ($item->isHit()) {

tests/Psr6StoreTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,15 @@ public function testRegularLookup()
342342

343343
$this->store->write($request, $response);
344344

345+
$this->assertSame('https://foobar.com/', $response->headers->get(Psr6Store::CACHE_DEBUG_HEADER));
346+
345347
$result = $this->store->lookup($request);
346348

347349
$this->assertInstanceOf(Response::class, $result);
348350
$this->assertSame(200, $result->getStatusCode());
349351
$this->assertSame('hello world', $result->getContent());
350352
$this->assertSame('whatever', $result->headers->get('Foobar'));
353+
$this->assertNull($result->headers->get(Psr6Store::CACHE_DEBUG_HEADER));
351354
}
352355

353356
public function testRegularLookupWithBinaryResponse()
@@ -364,6 +367,7 @@ public function testRegularLookupWithBinaryResponse()
364367
$this->assertSame(200, $result->getStatusCode());
365368
$this->assertSame(__DIR__.'/Fixtures/favicon.ico', $result->getFile()->getPathname());
366369
$this->assertSame('whatever', $result->headers->get('Foobar'));
370+
$this->assertNull($result->headers->get(Psr6Store::CACHE_DEBUG_HEADER));
367371
}
368372

369373
public function testRegularLookupWithRemovedBinaryResponse()

0 commit comments

Comments
 (0)