Skip to content

Commit 3291e70

Browse files
Fix live minification redirect issue
1 parent 7c6e3b9 commit 3291e70

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/HTMLMinServiceProvider.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
namespace GrahamCampbell\HTMLMin;
1818

19+
use Illuminate\Http\Response;
1920
use Illuminate\Support\ServiceProvider;
2021
use Illuminate\View\Engines\CompilerEngine;
2122

@@ -92,16 +93,19 @@ protected function enableLiveOptimisations()
9293

9394
// after filter
9495
$app->after(function ($request, $response) use ($app) {
95-
// check if the response has a content type header
96-
if ($response->headers->has('Content-Type') !== false) {
97-
// check if the contact type header is html
98-
if (strpos($response->headers->get('Content-Type'), 'text/html') !== false) {
99-
// get the response body
100-
$output = $response->getOriginalContent();
101-
// minify the response body
102-
$min = $app['htmlmin']->render($output);
103-
// set the response body
104-
$response->setContent($min);
96+
// check if the response is a real response and not a redirect
97+
if ($response instanceof Response) {
98+
// check if the response has a content type header
99+
if ($response->headers->has('Content-Type') !== false) {
100+
// check if the contact type header is html
101+
if (strpos($response->headers->get('Content-Type'), 'text/html') !== false) {
102+
// get the response body
103+
$output = $response->getOriginalContent();
104+
// minify the response body
105+
$min = $app['htmlmin']->render($output);
106+
// set the response body
107+
$response->setContent($min);
108+
}
105109
}
106110
}
107111
});

0 commit comments

Comments
 (0)