Skip to content

Commit 57cd1b4

Browse files
Merge branch '6.1' into 6.2
* 6.1: [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 [HttpClient] fix merge [HttpClient] Don't override header if is x-www-form-urlencoded [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 3b6c70d + fa931a5 commit 57cd1b4

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

HttpClientTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private static function prepareRequest(?string $method, ?string $url, array $opt
9494
}
9595

9696
if (isset($options['body'])) {
97-
if (\is_array($options['body'])) {
97+
if (\is_array($options['body']) && (!isset($options['normalized_headers']['content-type'][0]) || !str_contains($options['normalized_headers']['content-type'][0], 'application/x-www-form-urlencoded'))) {
9898
$options['normalized_headers']['content-type'] = ['Content-Type: application/x-www-form-urlencoded'];
9999
}
100100

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/HttpClientTraitTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ public function providePrepareRequestUrl(): iterable
4949
yield ['http://example.com/?b=', 'http://example.com/', ['a' => null, 'b' => '']];
5050
}
5151

52+
public function testPrepareRequestWithBodyIsArray()
53+
{
54+
$defaults = [
55+
'base_uri' => 'http://example.com?c=c',
56+
'query' => ['a' => 1, 'b' => 'b'],
57+
'body' => []
58+
];
59+
[, $defaults] = self::prepareRequest(null, null, $defaults);
60+
61+
[,$options] = self::prepareRequest(null, 'http://example.com', [
62+
'body' => [1, 2],
63+
'headers' => [
64+
'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'
65+
]
66+
], $defaults);
67+
68+
$this->assertContains('Content-Type: application/x-www-form-urlencoded; charset=utf-8', $options['headers']);
69+
}
70+
5271
/**
5372
* @dataProvider provideResolveUrl
5473
*/

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)