Skip to content

Commit

Permalink
Merge pull request #119 from Sebobo/bugfix/dont-break-responsehead
Browse files Browse the repository at this point in the history
BUGFIX: Don’t override response headers
  • Loading branch information
Sebobo authored Dec 14, 2020
2 parents bf5477b + f1f86f4 commit e52351e
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions Classes/Aspect/CollectDebugInformationAspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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 = '<!--__T3N_NEOS_DEBUG__ ' . json_encode($data) . '-->';
$htmlEndPosition = strpos($output, '</html>');

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;
}

/**
Expand Down

0 comments on commit e52351e

Please sign in to comment.