|
16 | 16 |
|
17 | 17 | namespace GrahamCampbell\HTMLMin;
|
18 | 18 |
|
| 19 | +use Illuminate\Http\Response; |
19 | 20 | use Illuminate\Support\ServiceProvider;
|
20 | 21 | use Illuminate\View\Engines\CompilerEngine;
|
21 | 22 |
|
@@ -92,16 +93,19 @@ protected function enableLiveOptimisations()
|
92 | 93 |
|
93 | 94 | // after filter
|
94 | 95 | $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 | + } |
105 | 109 | }
|
106 | 110 | }
|
107 | 111 | });
|
|
0 commit comments