Skip to content

Commit 89dc2f3

Browse files
mezhevikinnckg
authored andcommitted
Check if the content type header is html (#3)
1 parent 28f8282 commit 89dc2f3

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/Middleware/MinifyResponse.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,23 @@ public function handle($request, Closure $next)
2121
/** @var Response $response */
2222
$response = $next($request);
2323

24-
if (!app()->isLocal() and false === is_a($response, StreamedResponse::class)) {
24+
if (!app()->isLocal() && $this->isHtml($response)) {
2525
$response->setContent((new Minifier())->html($response->getContent()));
2626
}
2727

2828
return $response;
2929
}
30+
31+
/**
32+
* Check if the content type header is html.
33+
*
34+
* @param \Illuminate\Http\Response $response
35+
*
36+
* @return bool
37+
*/
38+
protected function isHtml($response)
39+
{
40+
$type = $response->headers->get('Content-Type');
41+
return strtolower(strtok($type, ';')) === 'text/html';
42+
}
3043
}

0 commit comments

Comments
 (0)