Skip to content

Commit 5882f85

Browse files
[HttpClient] fix throwing HTTP exceptions when the 1st chunk is emitted
1 parent 83815a5 commit 5882f85

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Response/ResponseTrait.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,20 +317,28 @@ public static function stream(iterable $responses, float $timeout = null): \Gene
317317
} elseif ($chunk instanceof ErrorChunk) {
318318
unset($responses[$j]);
319319
$isTimeout = true;
320-
} elseif ($chunk instanceof FirstChunk && $response->logger) {
321-
$info = $response->getInfo();
322-
$response->logger->info(sprintf('Response: "%s %s"', $info['http_code'], $info['url']));
320+
} elseif ($chunk instanceof FirstChunk) {
321+
if ($response->logger) {
322+
$info = $response->getInfo();
323+
$response->logger->info(sprintf('Response: "%s %s"', $info['http_code'], $info['url']));
324+
}
325+
326+
yield $response => $chunk;
327+
328+
if ($response->initializer && null === $response->info['error']) {
329+
// Ensure the HTTP status code is always checked
330+
$response->getHeaders(true);
331+
}
332+
333+
continue;
323334
}
324335

325336
yield $response => $chunk;
326337
}
327338

328339
unset($multi->handlesActivity[$j]);
329340

330-
if ($chunk instanceof FirstChunk && null === $response->initializer && null === $response->info['error']) {
331-
// Ensure the HTTP status code is always checked
332-
$response->getHeaders(true);
333-
} elseif ($chunk instanceof ErrorChunk && !$chunk->didThrow()) {
341+
if ($chunk instanceof ErrorChunk && !$chunk->didThrow()) {
334342
// Ensure transport exceptions are always thrown
335343
$chunk->getContent();
336344
}

0 commit comments

Comments
 (0)