|
12 | 12 | namespace Symfony\Component\HttpClient\Response;
|
13 | 13 |
|
14 | 14 | use Symfony\Component\HttpClient\Chunk\ErrorChunk;
|
15 |
| -use Symfony\Component\HttpClient\Chunk\FirstChunk; |
16 | 15 | use Symfony\Component\HttpClient\Chunk\LastChunk;
|
17 | 16 | use Symfony\Component\HttpClient\Exception\TransportException;
|
18 | 17 | use Symfony\Contracts\HttpClient\ChunkInterface;
|
@@ -245,7 +244,7 @@ public static function stream(iterable $responses, ?float $timeout = null, ?stri
|
245 | 244 | $wrappedResponses[] = $r->response;
|
246 | 245 |
|
247 | 246 | if ($r->stream) {
|
248 |
| - yield from self::passthruStream($response = $r->response, $r, new FirstChunk(), $asyncMap); |
| 247 | + yield from self::passthruStream($response = $r->response, $r, $asyncMap, new LastChunk()); |
249 | 248 |
|
250 | 249 | if (!isset($asyncMap[$response])) {
|
251 | 250 | array_pop($wrappedResponses);
|
@@ -276,15 +275,9 @@ public static function stream(iterable $responses, ?float $timeout = null, ?stri
|
276 | 275 | }
|
277 | 276 |
|
278 | 277 | if (!$r->passthru) {
|
279 |
| - if (null !== $chunk->getError() || $chunk->isLast()) { |
280 |
| - unset($asyncMap[$response]); |
281 |
| - } elseif (null !== $r->content && '' !== ($content = $chunk->getContent()) && \strlen($content) !== fwrite($r->content, $content)) { |
282 |
| - $chunk = new ErrorChunk($r->offset, new TransportException(\sprintf('Failed writing %d bytes to the response buffer.', \strlen($content)))); |
283 |
| - $r->info['error'] = $chunk->getError(); |
284 |
| - $r->response->cancel(); |
285 |
| - } |
| 278 | + $r->stream = (static fn () => yield $chunk)(); |
| 279 | + yield from self::passthruStream($response, $r, $asyncMap); |
286 | 280 |
|
287 |
| - yield $r => $chunk; |
288 | 281 | continue;
|
289 | 282 | }
|
290 | 283 |
|
@@ -347,13 +340,13 @@ private static function passthru(HttpClientInterface $client, self $r, ChunkInte
|
347 | 340 | }
|
348 | 341 | $r->stream = $stream;
|
349 | 342 |
|
350 |
| - yield from self::passthruStream($response, $r, null, $asyncMap); |
| 343 | + yield from self::passthruStream($response, $r, $asyncMap); |
351 | 344 | }
|
352 | 345 |
|
353 | 346 | /**
|
354 | 347 | * @param \SplObjectStorage<ResponseInterface, AsyncResponse>|null $asyncMap
|
355 | 348 | */
|
356 |
| - private static function passthruStream(ResponseInterface $response, self $r, ?ChunkInterface $chunk, ?\SplObjectStorage $asyncMap): \Generator |
| 349 | + private static function passthruStream(ResponseInterface $response, self $r, ?\SplObjectStorage $asyncMap, ?ChunkInterface $chunk = null): \Generator |
357 | 350 | {
|
358 | 351 | while (true) {
|
359 | 352 | try {
|
|
0 commit comments