diff --git a/src/Response/SapiStreamEmitter.php b/src/Response/SapiStreamEmitter.php index 6f0fe083..4655d565 100644 --- a/src/Response/SapiStreamEmitter.php +++ b/src/Response/SapiStreamEmitter.php @@ -62,14 +62,13 @@ private function emitBody(ResponseInterface $response, $maxBufferLength) $body->rewind(); } - if ($body->isReadable()) { - while (! $body->eof()) { - echo $body->read($maxBufferLength); - } - return; + if (! $body->isReadable()) { + echo $body; } - echo $body; + while (! $body->eof()) { + echo $body->read($maxBufferLength); + } } /** @@ -89,24 +88,26 @@ private function emitBodyRange(array $range, ResponseInterface $response, $maxBu if ($body->isSeekable()) { $body->seek($first); + $first = 0; } - if ($body->isReadable()) { - for ($remaining = $length; ($remaining >= $maxBufferLength) - && (! $body->eof()); $remaining -= strlen($contents)) { - echo ($contents = $body->read($maxBufferLength)); - } + if (! $body->isReadable()) { + echo substr($body->getContents(), $first, $length); + } - if (($remaining > 0) && (! $body->eof())) { - echo $body->read($remaining); - } + $remaining = $length; - return; + while ($remaining >= $maxBufferLength && ! $body->eof()) { + $contents = $body->read($maxBufferLength); + $remaining -= strlen($contents); + + echo $contents; } - $contents = $body->getContents(); - echo substr($contents, $first, $length); + if ($remaining > 0 && ! $body->eof()) { + echo $body->read($remaining); + } } /**