Spaces:
Running
Running
| namespace App\Http\Middleware; | |
| use Closure; | |
| class GzipMiddleware | |
| { | |
| /** | |
| * Handle an incoming request. | |
| * | |
| * @param \Illuminate\Http\Request $request | |
| * @param \Closure $next | |
| * @return mixed | |
| */ | |
| public function handle($request, Closure $next) | |
| { | |
| $response = $next($request); | |
| $content = $response->content(); | |
| $data = gzencode($content, 9); | |
| return response($data)->withHeaders([ | |
| 'Access-Control-Allow-Origin' => '*', | |
| 'Access-Control-Allow-Methods'=> 'GET', | |
| 'Content-Length'=> strlen($data), | |
| 'Content-Encoding' => 'gzip' | |
| ]); | |
| } | |
| } |