Skip to content

Commit 993525a

Browse files
[HttpClient] Fix dealing with empty responses in AsyncResponse
1 parent 1f7b8fd commit 993525a

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,13 @@ public static function stream(iterable $responses, float $timeout = null, string
206206
foreach ($client->stream($wrappedResponses, $timeout) as $response => $chunk) {
207207
$r = $asyncMap[$response];
208208

209-
if (null === $chunk->getError() && $chunk->isFirst()) {
210-
// Ensure no exception is thrown on destruct for the wrapped response
211-
$r->response->getStatusCode();
209+
if (null === $chunk->getError() && 0 === $r->offset) {
210+
if ($chunk->isFirst()) {
211+
// Ensure no exception is thrown on destruct for the wrapped response
212+
$r->response->getStatusCode();
213+
} elseif (null === $r->content && $chunk->isLast()) {
214+
$r->content = fopen('php://memory', 'w+');
215+
}
212216
}
213217

214218
if (!$r->passthru) {

0 commit comments

Comments
 (0)