Skip to content

Commit 6ca2d40

Browse files
committed
fix #49: disable boost inject if HTML isn't expected
1 parent 145ce63 commit 6ca2d40

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Middleware/InjectBoost.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function handle(Request $request, Closure $next): Response
1717
/** @var \Symfony\Component\HttpFoundation\Response $response */
1818
$response = $next($request);
1919

20-
if ($this->shouldInject($response->getContent())) {
20+
if ($this->shouldInject($response)) {
2121
$originalView = $response->original ?? null;
2222
$injectedContent = $this->injectScript($response->getContent());
2323
$response->setContent($injectedContent);
@@ -30,8 +30,13 @@ public function handle(Request $request, Closure $next): Response
3030
return $response;
3131
}
3232

33-
private function shouldInject(string $content): bool
33+
private function shouldInject(Response $response): bool
3434
{
35+
if (str_contains($response->headers->get('content-type'), 'html') === false) {
36+
return false;
37+
}
38+
39+
$content = $response->getContent();
3540
// Check if it's HTML
3641
if (! str_contains($content, '<html') && ! str_contains($content, '<head')) {
3742
return false;

0 commit comments

Comments
 (0)