diff --git a/Response/AsyncContext.php b/Response/AsyncContext.php index 9aacc70..5590346 100644 --- a/Response/AsyncContext.php +++ b/Response/AsyncContext.php @@ -184,9 +184,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/Tests/RetryableHttpClientTest.php b/Tests/RetryableHttpClientTest.php index 85a03fd..b81de09 100644 --- a/Tests/RetryableHttpClientTest.php +++ b/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'); + } }