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

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/Symfony/Component/HttpClient/Response/AsyncResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct(HttpClientInterface $client, string $method, string
while (true) {
foreach (self::stream([$response], $timeout) as $chunk) {
if ($chunk->isTimeout() && $response->passthru) {
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, new TransportException($chunk->getError()))) as $chunk) {
foreach (self::passthru($response->client, $response, new ErrorChunk($response->offset, $chunk->getError())) as $chunk) {
if ($chunk->isFirst()) {
return false;
}
Expand Down Expand Up @@ -123,9 +123,6 @@ public function getInfo(?string $type = null)
return $this->info + $this->response->getInfo();
}

/**
* {@inheritdoc}
*/
public function toStream(bool $throw = true)
{
if ($throw) {
Expand All @@ -146,9 +143,6 @@ public function toStream(bool $throw = true)
return $stream;
}

/**
* {@inheritdoc}
*/
public function cancel(): void
{
if ($this->info['canceled']) {
Expand Down
31 changes: 31 additions & 0 deletions src/Symfony/Component/HttpClient/Tests/RetryableHttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\Exception\ServerException;
use Symfony\Component\HttpClient\Exception\TimeoutException;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\NativeHttpClient;
Expand All @@ -21,6 +22,7 @@
use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;
use Symfony\Component\HttpClient\RetryableHttpClient;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\Test\TestHttpServer;

class RetryableHttpClientTest extends TestCase
{
Expand Down Expand Up @@ -244,4 +246,33 @@ public function testRetryOnErrorAssertContent()
self::assertSame('Test out content', $response->getContent());
self::assertSame('Test out content', $response->getContent(), 'Content should be buffered');
}

/**
* @testWith ["GET"]
* ["POST"]
* ["PUT"]
* ["PATCH"]
* ["DELETE"]
*/
public function testRetryOnHeaderTimeout(string $method)
{
$client = HttpClient::create();

if ($client instanceof NativeHttpClient) {
$this->markTestSkipped('NativeHttpClient cannot timeout before receiving headers');
}

TestHttpServer::start();

$client = new RetryableHttpClient($client);
$response = $client->request($method, 'http://localhost:8057/timeout-header', ['timeout' => 0.1]);

try {
$response->getStatusCode();
$this->fail(TimeoutException::class.' expected');
} catch (TimeoutException $e) {
}

$this->assertSame('Idle timeout reached for "http://localhost:8057/timeout-header".', $response->getInfo('error'));
}
}