Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c8b1806

Browse files
committed
[HttpClient] Fix error chunk creation in passthru
1 parent 90911f1 commit c8b1806

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

src/Symfony/Component/HttpClient/Response/AsyncResponse.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(HttpClientInterface $client, string $method, string
6565
while (true) {
6666
foreach (self::stream([$response], $timeout) as $chunk) {
6767
if ($chunk->isTimeout() && $response->passthru) {
68-
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, new TransportException($chunk->getError()))) as $chunk) {
68+
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, $chunk->getError())) as $chunk) {
6969
if ($chunk->isFirst()) {
7070
return false;
7171
}
@@ -123,9 +123,6 @@ public function getInfo(?string $type = null)
123123
return $this->info + $this->response->getInfo();
124124
}
125125

126-
/**
127-
* {@inheritdoc}
128-
*/
129126
public function toStream(bool $throw = true)
130127
{
131128
if ($throw) {
@@ -146,9 +143,6 @@ public function toStream(bool $throw = true)
146143
return $stream;
147144
}
148145

149-
/**
150-
* {@inheritdoc}
151-
*/
152146
public function cancel(): void
153147
{
154148
if ($this->info['canceled']) {

src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpClient\Exception\ServerException;
16+
use Symfony\Component\HttpClient\Exception\TimeoutException;
1617
use Symfony\Component\HttpClient\HttpClient;
1718
use Symfony\Component\HttpClient\MockHttpClient;
1819
use Symfony\Component\HttpClient\NativeHttpClient;
@@ -21,6 +22,7 @@
2122
use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;
2223
use Symfony\Component\HttpClient\RetryableHttpClient;
2324
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
25+
use Symfony\Contracts\HttpClient\Test\TestHttpServer;
2426

2527
class RetryableHttpClientTest extends TestCase
2628
{
@@ -244,4 +246,38 @@ public function testRetryOnErrorAssertContent()
244246
self::assertSame('Test out content', $response->getContent());
245247
self::assertSame('Test out content', $response->getContent(), 'Content should be buffered');
246248
}
249+
250+
/**
251+
* @dataProvider provideMethodForHeaderTimeout
252+
*/
253+
public function testRetryOnHeaderTimeout(string $method)
254+
{
255+
$client = HttpClient::create();
256+
257+
if ($client instanceof NativeHttpClient) {
258+
$this->markTestSkipped('NativeHttpClient cannot timeout before receiving headers');
259+
}
260+
261+
TestHttpServer::start();
262+
263+
$client = new RetryableHttpClient($client);
264+
$response = $client->request($method, 'http://localhost:8057/timeout-header', ['timeout' => 0.1]);
265+
266+
try {
267+
$response->getStatusCode();
268+
$this->fail(TimeoutException::class.' expected');
269+
} catch (TimeoutException $e) {
270+
}
271+
272+
$this->assertSame('Idle timeout reached for "http://localhost:8057/timeout-header".', $response->getInfo('error'));
273+
}
274+
275+
public function provideMethodForHeaderTimeout(): iterable
276+
{
277+
yield ['GET'];
278+
yield ['POST'];
279+
yield ['PUT'];
280+
yield ['PATCH'];
281+
yield ['DELETE'];
282+
}
247283
}

0 commit comments

Comments
 (0)