Skip to content

Commit f8d4168

Browse files
bug #47441 [HttpClient] [HttpClientBundle] Bugfix for delayed retryableHttpClient (martkop26)
This PR was submitted for the 6.2 branch but it was squashed and merged into the 5.4 branch instead. Discussion ---------- [HttpClient] [HttpClientBundle] Bugfix for delayed retryableHttpClient | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #47430 | License | MIT Commits ------- 87738ba [HttpClient] Fix computing retry delay when using RetryableHttpClient
2 parents af1ab9e + 87738ba commit f8d4168

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Symfony/Component/HttpClient/RetryableHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private function getDelayFromHeader(array $headers): ?int
138138
{
139139
if (null !== $after = $headers['retry-after'][0] ?? null) {
140140
if (is_numeric($after)) {
141-
return (int) $after * 1000;
141+
return (int) ($after * 1000);
142142
}
143143

144144
if (false !== $time = strtotime($after)) {

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,42 @@ public function testCancelOnTimeout()
187187
$response->cancel();
188188
}
189189
}
190+
191+
public function testRetryWithDelay()
192+
{
193+
$retryAfter = '0.46';
194+
195+
$client = new RetryableHttpClient(
196+
new MockHttpClient([
197+
new MockResponse('', [
198+
'http_code' => 503,
199+
'response_headers' => [
200+
'retry-after' => $retryAfter,
201+
],
202+
]),
203+
new MockResponse('', [
204+
'http_code' => 200,
205+
]),
206+
]),
207+
new GenericRetryStrategy(),
208+
1,
209+
$logger = new class() extends TestLogger {
210+
public array $context = [];
211+
212+
public function log($level, $message, array $context = []): void
213+
{
214+
$this->context = $context;
215+
parent::log($level, $message, $context);
216+
}
217+
},
218+
);
219+
220+
$client->request('GET', 'http://example.com/foo-bar')->getContent();
221+
222+
$delay = $logger->context['delay'] ?? null;
223+
224+
$this->assertArrayHasKey('delay', $logger->context);
225+
$this->assertNotNull($delay);
226+
$this->assertSame((int) ($retryAfter * 1000), $delay);
227+
}
190228
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy