diff --git a/src/Symfony/Component/HttpClient/Response/AsyncContext.php b/src/Symfony/Component/HttpClient/Response/AsyncContext.php index 2d95e11f507f1..646458e13c54e 100644 --- a/src/Symfony/Component/HttpClient/Response/AsyncContext.php +++ b/src/Symfony/Component/HttpClient/Response/AsyncContext.php @@ -181,9 +181,15 @@ public function replaceResponse(ResponseInterface $response): ResponseInterface /** * Replaces or removes the chunk filter iterator. + * + * @param ?callable(ChunkInterface, self): ?\Iterator $passthru */ public function passthru(callable $passthru = null): void { - $this->passthru = $passthru; + $this->passthru = $passthru ?? static function ($chunk, $context) { + $context->passthru = null; + + yield $chunk; + }; } } diff --git a/src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php b/src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php index 85a03fd225183..b81de09c25a16 100644 --- a/src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php @@ -225,4 +225,22 @@ public function log($level, $message, array $context = []): void $this->assertNotNull($delay); $this->assertSame((int) ($retryAfter * 1000), $delay); } + + public function testRetryOnErrorAssertContent() + { + $client = new RetryableHttpClient( + new MockHttpClient([ + new MockResponse('', ['http_code' => 500]), + new MockResponse('Test out content', ['http_code' => 200]), + ]), + new GenericRetryStrategy([500], 0), + 1 + ); + + $response = $client->request('GET', 'http://example.com/foo-bar'); + + self::assertSame(200, $response->getStatusCode()); + self::assertSame('Test out content', $response->getContent()); + self::assertSame('Test out content', $response->getContent(), 'Content should be buffered'); + } }