8000 bug #38418 [HttpClient] minor fixes in RetryableHttpClient (nicolas-g… · symfony/symfony@a324b22 · GitHub
[go: up one dir, main page]

Skip to content

Commit a324b22

Browse files
committed
bug #38418 [HttpClient] minor fixes in RetryableHttpClient (nicolas-grekas)
This PR was merged into the 5.2-dev branch. Discussion ---------- [HttpClient] minor fixes in RetryableHttpClient | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 4955628 [HttpClient] minor fixes in RetryableHttpClient
2 parents a4ceab6 + 4955628 commit a324b22

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/Symfony/Component/HttpClient/Response/AsyncResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ final class AsyncResponse implements ResponseInterface, StreamableInterface
3636
private $passthru;
3737

3838
/**
39-
* @param callable(ChunkInterface, AsyncContext): ?\Iterator $passthru
39+
* @param ?callable(ChunkInterface, AsyncContext): ?\Iterator $passthru
4040
*/
41-
public function __construct(HttpClientInterface $client, string $method, string $url, array $options, callable $passthru)
41+
public function __construct(HttpClientInterface $client, string $method, string $url, array $options, callable $passthru = null)
4242
{
4343
$this->client = $client;
4444
$this->shouldBuffer = $options['buffer'] ?? true;

src/Symfony/Component/HttpClient/RetryableHttpClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(HttpClientInterface $client, RetryDeciderInterface $
5353
public function request(string $method, string $url, array $options = []): ResponseInterface
5454
{
5555
if ($this->maxRetries <= 0) {
56-
return $this->client->request($method, $url, $options);
56+
return new AsyncResponse($this->client, $method, $url, $options);
5757
}
5858

5959
$retryCount = 0;
@@ -97,7 +97,7 @@ public function request(string $method, string $url, array $options = []): Respo
9797
if (!$chunk->isLast()) {
9898
return;
9999
}
100-
$shouldRetry = $this->decider->shouldRetry($method, $url, $options, $statusCode, $headers, $content, null);
100+
$shouldRetry = $this->decider->shouldRetry($method, $url, $options, $statusCode, $headers, $content);
101101
if (null === $shouldRetry) {
102102
throw new \LogicException(sprintf('The "%s::shouldRetry" method must not return null when called with a body.', \get_class($this->decider)));
103103
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,24 @@ public function shouldRetry(string $requestMethod, string $requestUrl, array $re
9393
$this->expectExceptionMessageMatches('/must not return null when called with a body/');
9494
$response->getHeaders();
9595
}
96+
97+
public function testStreamNoRetry()
98+
{
99+
$client = new RetryableHttpClient(
100+
new MockHttpClient([
101+
new MockResponse('', ['http_code' => 500]),
102+
]),
103+
new HttpStatusCodeDecider([500]),
104+
new ExponentialBackOff(0),
105+
0
106+
);
107+
108+
$response = $client->request('GET', 'http://example.com/foo-bar');
109+
110+
foreach ($client->stream($response) as $chunk) {
111+
if ($chunk->isFirst()) {
112+
self::assertSame(500, $response->getStatusCode());
113+
}
114+
}
115+
}
96116
}

0 commit comments

Comments
 (0)
0