From f1f86f42ae4d272615ee210349618c0f6a282ec8 Mon Sep 17 00:00:00 2001 From: Sebastian Helzle Date: Mon, 14 Dec 2020 16:24:43 +0100 Subject: [PATCH] =?UTF-8?q?BUGFIX:=20Don=E2=80=99t=20override=20response?= =?UTF-8?q?=20headers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With this change the rendered response is handled correctly if it’s not a plain string. Resolves: #105 --- .../Aspect/CollectDebugInformationAspect.php | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/Classes/Aspect/CollectDebugInformationAspect.php b/Classes/Aspect/CollectDebugInformationAspect.php index 120acdd..d61fd43 100644 --- a/Classes/Aspect/CollectDebugInformationAspect.php +++ b/Classes/Aspect/CollectDebugInformationAspect.php @@ -15,6 +15,8 @@ */ use Doctrine\ORM\EntityManagerInterface; +use GuzzleHttp\Psr7\Response; +use GuzzleHttp\Psr7\Utils; use Neos\Flow\Annotations as Flow; use Neos\Flow\Aop\JoinPointInterface; use t3n\Neos\Debug\Logging\DebugStack; @@ -80,11 +82,13 @@ public function debuggingActive(): void * @Flow\Around("method(Neos\Neos\View\FusionView->render()) && t3n\Neos\Debug\Aspect\CollectDebugInformationAspect->debuggingActive") * * @param \Neos\Flow\AOP\JoinPointInterface $joinPoint + * + * @return string|Response */ - public function addDebugValues(JoinPointInterface $joinPoint): string + public function addDebugValues(JoinPointInterface $joinPoint) { $startRenderAt = microtime(true) * 1000; - $output = $joinPoint->getAdviceChain()->proceed($joinPoint); + $response = $joinPoint->getAdviceChain()->proceed($joinPoint); $endRenderAt = microtime(true) * 1000; $renderTime = round($endRenderAt - $startRenderAt, 2); @@ -100,6 +104,16 @@ public function addDebugValues(JoinPointInterface $joinPoint): string } } + if (! $this->htmlOutputEnabled) { + return $response; + } + + if ($response instanceof Response) { + $output = $response->getBody()->getContents(); + } else { + $output = $response; + } + $data = [ 'startRenderAt' => $startRenderAt, 'endRenderAt' => $endRenderAt, @@ -114,22 +128,19 @@ public function addDebugValues(JoinPointInterface $joinPoint): string 'cCacheMisses' => $this->contentCacheMisses, ]; - if ($output instanceof \GuzzleHttp\Psr7\Response) { - $output = $output->getBody()->getContents(); - } - - if (! $this->htmlOutputEnabled) { - return $output; - } - $debugOutput = ''; $htmlEndPosition = strpos($output, ''); if ($htmlEndPosition === false) { - return $output . $debugOutput; + $output .= $debugOutput; + } else { + $output = substr($output, 0, $htmlEndPosition) . $debugOutput . substr($output, $htmlEndPosition); } - return substr($output, 0, $htmlEndPosition) . $debugOutput . substr($output, $htmlEndPosition); + if ($response instanceof Response) { + return $response->withBody(Utils::streamFor($output)); + } + return $output; } /**