Skip to content

Commit 31797f9

Browse files
Merge branch '5.4' into 6.0
* 5.4: [HttpKernel] Fix empty request stack when terminating with exception [HttpKernel] Remove EOL when using error_log() in HttpKernel Logger [HttpClient] Add test case for seeking into the content of RetryableHttpClient responses [HttpClient] Fix buffering after calling AsyncContext::passthru() s/annd/and s/gargage/garbage [Console] Fix error output on windows cli Reserve keys when using numeric ones add missing Azerbaijani translations fix few typos/inconsistencies in latvian translations Fix TypeError in Router when using UrlGenerator [Messenger] Fix amqp socket lost fix: use message object from event
2 parents ec183a5 + 65cb8e8 commit 31797f9

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Response/AsyncContext.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,15 @@ public function replaceResponse(ResponseInterface $response): ResponseInterface
184184

185185
/**
186186
* Replaces or removes the chunk filter iterator.
187+
*
188+
* @param ?callable(ChunkInterface, self): ?\Iterator $passthru
187189
*/
188190
public function passthru(callable $passthru = null): void
189191
{
190-
$this->passthru = $passthru;
192+
$this->passthru = $passthru ?? static function ($chunk, $context) {
193+
$context->passthru = null;
194+
195+
yield $chunk;
196+
};
191197
}
192198
}

Tests/RetryableHttpClientTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,22 @@ public function log($level, $message, array $context = []): void
225225
$this->assertNotNull($delay);
226226
$this->assertSame((int) ($retryAfter * 1000), $delay);
227227
}
228+
229+
public function testRetryOnErrorAssertContent()
230+
{
231+
$client = new RetryableHttpClient(
232+
new MockHttpClient([
233+
new MockResponse('', ['http_code' => 500]),
234+
new MockResponse('Test out content', ['http_code' => 200]),
235+
]),
236+
new GenericRetryStrategy([500], 0),
237+
1
238+
);
239+
240+
$response = $client->request('GET', 'http://example.com/foo-bar');
241+
242+
self::assertSame(200, $response->getStatusCode());
243+
self::assertSame('Test out content', $response->getContent());
244+
self::assertSame('Test out content', $response->getContent(), 'Content should be buffered');
245+
}
228246
}

0 commit comments

Comments
 (0)