public function injectDebugbar(Response $response)
{
$content = $response->getContent();
$renderer = $this->getJavascriptRenderer();
if ($this->getStorage()) {
$openHandlerUrl = route('debugbar.openhandler');
$renderer->setOpenHandlerUrl($openHandlerUrl);
}
$renderedContent = $renderer->renderHead() . $renderer->render();
$pos = strripos($content, '</body>');
if (false !== $pos) {
$content = substr($content, 0, $pos) . $renderedContent . substr($content, $pos);
} else {
$content = $content . $renderedContent;
}
// Update the new content and reset the content length
$response->setContent($content);
$response->headers->remove('Content-Length');
}