diff --git a/Neos.Flow/Classes/Error/DebugExceptionHandler.php b/Neos.Flow/Classes/Error/DebugExceptionHandler.php index d3f490a2ca..3718a0e289 100644 --- a/Neos.Flow/Classes/Error/DebugExceptionHandler.php +++ b/Neos.Flow/Classes/Error/DebugExceptionHandler.php @@ -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); } diff --git a/Neos.Flow/Classes/Error/ProductionExceptionHandler.php b/Neos.Flow/Classes/Error/ProductionExceptionHandler.php index 5337e70c3f..a637f90e0e 100644 --- a/Neos.Flow/Classes/Error/ProductionExceptionHandler.php +++ b/Neos.Flow/Classes/Error/ProductionExceptionHandler.php @@ -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); } diff --git a/Neos.Flow/Classes/Http/Helper/ResponseInformationHelper.php b/Neos.Flow/Classes/Http/Helper/ResponseInformationHelper.php index 1858a2b88e..f120eba029 100644 --- a/Neos.Flow/Classes/Http/Helper/ResponseInformationHelper.php +++ b/Neos.Flow/Classes/Http/Helper/ResponseInformationHelper.php @@ -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. @@ -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; + } + } } diff --git a/Neos.Flow/Classes/Http/RequestHandler.php b/Neos.Flow/Classes/Http/RequestHandler.php index 2a65d6ad29..249780b287 100644 --- a/Neos.Flow/Classes/Http/RequestHandler.php +++ b/Neos.Flow/Classes/Http/RequestHandler.php @@ -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()); } }