Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion system/Cache/ResponseCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ public function make(CLIRequest|IncomingRequest $request, ResponseInterface $res

return $this->cache->save(
$this->generateCacheKey($request),
serialize(['headers' => $headers, 'output' => $response->getBody()]),
serialize([
'headers' => $headers,
'output' => $response->getBody(),
'statuscode' => $response->getStatusCode(),
'reasonphrase' => $response->getReasonPhrase(),
Comment thread
sk757a marked this conversation as resolved.
Outdated
]),
$this->ttl,
);
}
Expand Down Expand Up @@ -140,6 +145,10 @@ public function get(CLIRequest|IncomingRequest $request, ResponseInterface $resp

$response->setBody($output);

if (isset($cachedResponse['statuscode'])) {
$response->setStatusCode($cachedResponse['statuscode'], $cachedResponse['reasonphrase'] ?? '');
}

return $response;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/system/Cache/ResponseCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ public function testCachePageIncomingRequest(): void
$this->assertNotInstanceOf(ResponseInterface::class, $cachedResponse);
}

public function testCachePageIncomingRequestWithStatus(): void
{
$pageCache = $this->createResponseCache();

$response = new Response(new App());
$response->setStatusCode(432, 'Foo Bar');
$response->setBody('The response body.');

$this->assertTrue($pageCache->make($this->createIncomingRequest('foo/bar'), $response));

// Check cached response status
$cachedResponse = $pageCache->get($this->createIncomingRequest('foo/bar'), new Response(new App()));
$this->assertInstanceOf(ResponseInterface::class, $cachedResponse);
$this->assertSame(432, $cachedResponse->getStatusCode());
$this->assertSame('Foo Bar', $cachedResponse->getReasonPhrase());
}

public function testCachePageIncomingRequestWithCacheQueryString(): void
{
$cache = new Cache();
Expand Down