Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c83c07e

Browse filesBrowse files
bug #53506 [HttpClient] Fix error chunk creation in passthru (rmikalkenas)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpClient] Fix error chunk creation in passthru | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | #52587 | License | MIT Timeout chunk should not be recreated as TransportException, because ErrorChunk losts information that it's timeout when passing thru. Change solves issue mentioned at #52587 Commits ------- 5e6d218 [HttpClient] Fix error chunk creation in passthru
2 parents 90911f1 + 5e6d218 commit c83c07e
Copy full SHA for c83c07e

File tree

2 files changed

+32
-7
lines changed
Filter options

2 files changed

+32
-7
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/AsyncResponse.php
+1-7Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php
+31Lines changed: 31 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,33 @@ 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+
* @testWith ["GET"]
252+
* ["POST"]
253+
* ["PUT"]
254+
* ["PATCH"]
255+
* ["DELETE"]
256+
*/
257+
public function testRetryOnHeaderTimeout(string $method)
258+
{
259+
$client = HttpClient::create();
260+
261+
if ($client instanceof NativeHttpClient) {
262+
$this->markTestSkipped('NativeHttpClient cannot timeout before receiving headers');
263+
}
264+
265+
TestHttpServer::start();
266+
267+
$client = new RetryableHttpClient($client);
268+
$response = $client->request($method, 'http://localhost:8057/timeout-header', ['timeout' => 0.1]);
269+
270+
try {
271+
$response->getStatusCode();
272+
$this->fail(TimeoutException::class.' expected');
273+
} catch (TimeoutException $e) {
274+
}
275+
276+
$this->assertSame('Idle timeout reached for "http://localhost:8057/timeout-header".', $response->getInfo('error'));
277+
}
247278
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.