diff --git a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php index bf7ba3a746db2..8a1d9a9077ce1 100644 --- a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php +++ b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php @@ -317,9 +317,20 @@ public static function stream(iterable $responses, float $timeout = null): \Gene } elseif ($chunk instanceof ErrorChunk) { unset($responses[$j]); $isTimeout = true; - } elseif ($chunk instanceof FirstChunk && $response->logger) { - $info = $response->getInfo(); - $response->logger->info(sprintf('Response: "%s %s"', $info['http_code'], $info['url'])); + } elseif ($chunk instanceof FirstChunk) { + if ($response->logger) { + $info = $response->getInfo(); + $response->logger->info(sprintf('Response: "%s %s"', $info['http_code'], $info['url'])); + } + + yield $response => $chunk; + + if ($response->initializer && null === $response->info['error']) { + // Ensure the HTTP status code is always checked + $response->getHeaders(true); + } + + continue; } yield $response => $chunk; @@ -327,10 +338,7 @@ public static function stream(iterable $responses, float $timeout = null): \Gene unset($multi->handlesActivity[$j]); - if ($chunk instanceof FirstChunk && null === $response->initializer && null === $response->info['error']) { - // Ensure the HTTP status code is always checked - $response->getHeaders(true); - } elseif ($chunk instanceof ErrorChunk && !$chunk->didThrow()) { + if ($chunk instanceof ErrorChunk && !$chunk->didThrow()) { // Ensure transport exceptions are always thrown $chunk->getContent(); } diff --git a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php index 932614dff3ae2..0547c752ac9d5 100644 --- a/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php +++ b/src/Symfony/Contracts/HttpClient/Test/HttpClientTestCase.php @@ -152,6 +152,16 @@ public function testClientError() $this->assertSame(404, $response->getStatusCode()); $this->assertSame(['application/json'], $response->getHeaders(false)['content-type']); $this->assertNotEmpty($response->getContent(false)); + + $response = $client->request('GET', 'http://localhost:8057/404'); + + try { + foreach ($client->stream($response) as $chunk) { + $this->assertTrue($chunk->isFirst()); + } + $this->fail(ClientExceptionInterface::class.' expected'); + } catch (ClientExceptionInterface $e) { + } } public function testIgnoreErrors() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy