Skip to content

Commit 1180fd6

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: Typos In Comments typo s/retrieveing/retrieving Typos on 6.0 branch remove duplicated catch block s/<\br>/<br> [HttpClient] Fix retrying requests when the content is used by the strategy
2 parents e712523 + f515d06 commit 1180fd6

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

RetryableHttpClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function request(string $method, string $url, array $options = []): Respo
6060
return new AsyncResponse($this->client, $method, $url, $options, function (ChunkInterface $chunk, AsyncContext $context) use ($method, $url, $options, &$retryCount, &$content, &$firstChunk) {
6161
$exception = null;
6262
try {
63-
if ($chunk->isTimeout() || null !== $chunk->getInformationalStatus() || $context->getInfo('canceled')) {
63+
if ($context->getInfo('canceled') || $chunk->isTimeout() || null !== $chunk->getInformationalStatus()) {
6464
yield $chunk;
6565

6666
return;
@@ -118,6 +118,8 @@ public function request(string $method, string $url, array $options = []): Respo
118118

119119
$delay = $this->getDelayFromHeader($context->getHeaders()) ?? $this->strategy->getDelay($context, !$exception && $chunk->isLast() ? $content : null, $exception);
120120
++$retryCount;
121+
$content = '';
122+
$firstChunk = null;
121123

122124
$this->logger->info('Try #{count} after {delay}ms'.($exception ? ': '.$exception->getMessage() : ', status code: '.$context->getStatusCode()), [
123125
'count' => $retryCount,

Tests/RetryableHttpClientTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,22 @@ public function testRetryWithBody()
6262
{
6363
$client = new RetryableHttpClient(
6464
new MockHttpClient([
65-
new MockResponse('', ['http_code' => 500]),
66-
new MockResponse('', ['http_code' => 200]),
65+
new MockResponse('abc', ['http_code' => 500]),
66+
new MockResponse('def', ['http_code' => 200]),
6767
]),
6868
new class(GenericRetryStrategy::DEFAULT_RETRY_STATUS_CODES, 0) extends GenericRetryStrategy {
6969
public function shouldRetry(AsyncContext $context, ?string $responseContent, ?TransportExceptionInterface $exception): ?bool
7070
{
71-
return null === $responseContent ? null : 200 !== $context->getStatusCode();
71+
return 500 === $context->getStatusCode() && null === $responseContent ? null : 200 !== $context->getStatusCode();
7272
}
7373
},
74-
1
74+
2
7575
);
7676

7777
$response = $client->request('GET', 'http://example.com/foo-bar');
7878

7979
self::assertSame(200, $response->getStatusCode());
80+
self::assertSame('def', $response->getContent());
8081
}
8182

8283
public function testRetryWithBodyKeepContent()

0 commit comments

Comments
 (0)