diff --git a/src/PhpDebugBarMiddleware.php b/src/PhpDebugBarMiddleware.php index 4bb20ee..6856bb8 100644 --- a/src/PhpDebugBarMiddleware.php +++ b/src/PhpDebugBarMiddleware.php @@ -48,7 +48,11 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res $debugBarBody = $this->debugBarRenderer->render(); if ($this->isHtmlResponse($outResponse)) { - $outResponse->getBody()->write($debugBarHead . $debugBarBody); + $body = $outResponse->getBody(); + if (! $body->eof() && $body->isSeekable()) { + $body->seek(0, SEEK_END); + } + $body->write($debugBarHead . $debugBarBody); return $outResponse; } diff --git a/test/PhpDebugBarMiddlewareTest.php b/test/PhpDebugBarMiddlewareTest.php index 5169a55..1f6766c 100644 --- a/test/PhpDebugBarMiddlewareTest.php +++ b/test/PhpDebugBarMiddlewareTest.php @@ -80,4 +80,25 @@ public function testAttachToHtmlResponse() $this->assertSame($response, $result); $this->assertSame("ResponseBodyRenderHeadRenderBody", (string) $result->getBody()); } + + public function testAppendsToEndOfHtmlResponse() + { + $html = '