Skip to content

Commit

Permalink
TASK: Refactor stream sending
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Mar 16, 2024
1 parent ae2bcb5 commit 7b04e7b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
8 changes: 1 addition & 7 deletions Neos.Flow/Classes/Error/DebugExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,7 @@ protected function echoExceptionWeb($exception)
*/
$stream = $stream->getBody();
}
$resourceOrString = $stream->detach() ?: $stream->getContents();
if (is_resource($resourceOrString)) {
fpassthru($resourceOrString);
fclose($resourceOrString);
} else {
echo $resourceOrString;
}
ResponseInformationHelper::sendStream($stream);
} catch (\Throwable $throwable) {
$this->renderStatically($statusCode, $throwable);
}
Expand Down
8 changes: 1 addition & 7 deletions Neos.Flow/Classes/Error/ProductionExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ protected function echoExceptionWeb($exception)
*/
$stream = $stream->getBody();
}
$resourceOrString = $stream->detach() ?: $stream->getContents();
if (is_resource($resourceOrString)) {
fpassthru($resourceOrString);
fclose($resourceOrString);
} else {
echo $resourceOrString;
}
ResponseInformationHelper::sendStream($stream);
} catch (\Throwable $throwable) {
$this->renderStatically($statusCode, $throwable);
}
Expand Down
12 changes: 12 additions & 0 deletions Neos.Flow/Classes/Http/Helper/ResponseInformationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Neos\Flow\Http\CacheControlDirectives;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;

/**
* Helper to extract various information from PSR-7 responses.
Expand Down Expand Up @@ -242,4 +243,15 @@ public static function makeStandardsCompliant(ResponseInterface $response, Reque

return $response;
}

public static function sendStream(StreamInterface $stream): void
{
$body = $stream->detach() ?: $stream->getContents();
if (is_resource($body)) {
fpassthru($body);
fclose($body);
} else {
echo $body;
}
}
}
8 changes: 1 addition & 7 deletions Neos.Flow/Classes/Http/RequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,6 @@ protected function sendResponse(ResponseInterface $response)
ob_end_flush();
}

$body = $response->getBody()->detach() ?: $response->getBody()->getContents();
if (is_resource($body)) {
fpassthru($body);
fclose($body);
} else {
echo $body;
}
ResponseInformationHelper::sendStream($response->getBody());
}
}

0 comments on commit 7b04e7b

Please sign in to comment.