Skip to content
This repository was archived by the owner on Jun 27, 2022. It is now read-only.

Commit 77246ff

Browse files
committed
Increment the age of the response #59
1 parent 6e31045 commit 77246ff

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/Utils.php

+7-8
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,7 @@ public static function getDirective(MessageInterface $message, $part)
4444
public static function getResponseAge(ResponseInterface $response)
4545
{
4646
if ($response->hasHeader('Age')) {
47-
$age = (int) $response->getHeader('Age');
48-
49-
// Increment the age based on the X-Guzzle-Cache-Date
50-
if ($cacheDate = $response->getHeader('X-Guzzle-Cache-Date')) {
51-
$age += (time() - strtotime($cacheDate));
52-
}
53-
54-
return $age;
47+
return (int) $response->getHeader('Age');
5548
}
5649

5750
$date = strtotime($response->getHeader('Date') ?: 'now');
@@ -179,6 +172,12 @@ public static function isResponseValid(
179172
$responseAge = Utils::getResponseAge($response);
180173
$maxAge = Utils::getDirective($response, 'max-age');
181174

175+
// Increment the age based on the X-Guzzle-Cache-Date
176+
if ($cacheDate = $response->getHeader('X-Guzzle-Cache-Date')) {
177+
$responseAge += (time() - strtotime($cacheDate));
178+
$response->setHeader('Age', $responseAge);
179+
}
180+
182181
// Check the request's max-age header against the age of the response
183182
if ($maxAge !== null && $responseAge > $maxAge) {
184183
return false;

0 commit comments

Comments
 (0)