From c1da0eb6d5ec706181f8424791bac5bb0d0f84a2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 18 Oct 2022 14:02:10 +0200 Subject: [PATCH 1/2] [HttpClient] Fix buffering after calling AsyncContext::passthru() --- .../Component/HttpClient/Response/AsyncContext.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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; + }; } } From b559f80812cdbf8fdac1d39ad2d17119646b3326 Mon Sep 17 00:00:00 2001 From: Lyubomir Grozdanov Date: Sun, 16 Oct 2022 19:35:13 +0300 Subject: [PATCH 2/2] [HttpClient] Add test case for seeking into the content of RetryableHttpClient responses --- .../Tests/RetryableHttpClientTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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'); + } }