Skip to content

Commit 79820e8

Browse files
bug #62728 [HttpClient] mark response stale when age equals freshness lifetime (Lctrs)
This PR was merged into the 7.4 branch. Discussion ---------- [HttpClient] mark response stale when age equals freshness lifetime | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | yes | New feature? | no <!-- if yes, also update src/**/CHANGELOG.md --> | Deprecations? | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md --> | Issues | | License | MIT <!-- 🛠️ Replace this text with a concise explanation of your change: - What it does and why it's needed - A simple example of how it works (include PHP, YAML, etc.) - If it modifies existing behavior, include a before/after comparison Contributor guidelines: - ✅ Add tests and ensure they pass - 🐞 Bug fixes must target the **lowest maintained** branch where they apply https://symfony.com/releases#maintained-symfony-branches - ✨ New features and deprecations must target the **feature** branch and must add an entry to the changelog file of the patched component: https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - 🔒 Do not break backward compatibility: https://symfony.com/bc --> Commits ------- 208a76d [HttpClient] mark response stale when age equals freshness lifetime
2 parents dd2be4c + 208a76d commit 79820e8

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/Symfony/Component/HttpClient/CachingHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ private function evaluateCacheFreshness(array $data): Freshness
559559
$now = time();
560560
$expires = $data['expires_at'];
561561

562-
if (null !== $expires && $now <= $expires) {
562+
if (null !== $expires && $now < $expires) {
563563
return Freshness::Fresh;
564564
}
565565

src/Symfony/Component/HttpClient/Tests/CachingHttpClientTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ public function testItDoesntServeAStaleResponse()
172172
self::assertSame(200, $response->getStatusCode());
173173
self::assertSame('foo', $response->getContent());
174174

175-
sleep(5);
175+
sleep(4);
176176

177-
// After 5 seconds, the cached response is still considered valid.
177+
// After 4 seconds, the cached response is still considered valid.
178178
$response = $client->request('GET', 'http://example.com/foo-bar');
179179
self::assertSame(200, $response->getStatusCode());
180180
self::assertSame('foo', $response->getContent());
@@ -954,14 +954,14 @@ public function testHeuristicFreshnessWithLastModified()
954954
self::assertSame('foo', $response->getContent());
955955

956956
// Heuristic: 10% of 3600s = 360s; should be fresh within this time
957-
sleep(360); // 5 minutes
957+
sleep(359); // 5 minutes
958958

959959
$response = $client->request('GET', 'http://example.com/heuristic');
960960
self::assertSame(200, $response->getStatusCode());
961961
self::assertSame('foo', $response->getContent());
962962

963963
// After heuristic expires
964-
sleep(1); // Total 361s, past 360s heuristic
964+
sleep(2); // Total 361s, past 360s heuristic
965965

966966
$response = $client->request('GET', 'http://example.com/heuristic');
967967
self::assertSame(200, $response->getStatusCode());

0 commit comments

Comments
 (0)