@@ -35,56 +35,56 @@ |
||
35 | 35 | |
36 | 36 | class CompressionMiddleware extends Middleware { |
37 | 37 | |
38 | - /** @var bool */ |
|
39 | - private $useGZip; |
|
38 | + /** @var bool */ |
|
39 | + private $useGZip; |
|
40 | 40 | |
41 | - /** @var IRequest */ |
|
42 | - private $request; |
|
41 | + /** @var IRequest */ |
|
42 | + private $request; |
|
43 | 43 | |
44 | - public function __construct(IRequest $request) { |
|
45 | - $this->request = $request; |
|
46 | - $this->useGZip = false; |
|
47 | - } |
|
44 | + public function __construct(IRequest $request) { |
|
45 | + $this->request = $request; |
|
46 | + $this->useGZip = false; |
|
47 | + } |
|
48 | 48 | |
49 | - public function afterController($controller, $methodName, Response $response) { |
|
50 | - // By default we do not gzip |
|
51 | - $allowGzip = false; |
|
49 | + public function afterController($controller, $methodName, Response $response) { |
|
50 | + // By default we do not gzip |
|
51 | + $allowGzip = false; |
|
52 | 52 | |
53 | - // Only return gzipped content for 200 responses |
|
54 | - if ($response->getStatus() !== Http::STATUS_OK) { |
|
55 | - return $response; |
|
56 | - } |
|
53 | + // Only return gzipped content for 200 responses |
|
54 | + if ($response->getStatus() !== Http::STATUS_OK) { |
|
55 | + return $response; |
|
56 | + } |
|
57 | 57 | |
58 | - // Check if we are even asked for gzip |
|
59 | - $header = $this->request->getHeader('Accept-Encoding'); |
|
60 | - if (strpos($header, 'gzip') === false) { |
|
61 | - return $response; |
|
62 | - } |
|
58 | + // Check if we are even asked for gzip |
|
59 | + $header = $this->request->getHeader('Accept-Encoding'); |
|
60 | + if (strpos($header, 'gzip') === false) { |
|
61 | + return $response; |
|
62 | + } |
|
63 | 63 | |
64 | - // We only allow gzip in some cases |
|
65 | - if ($response instanceof BaseResponse) { |
|
66 | - $allowGzip = true; |
|
67 | - } |
|
68 | - if ($response instanceof JSONResponse) { |
|
69 | - $allowGzip = true; |
|
70 | - } |
|
71 | - if ($response instanceof TemplateResponse) { |
|
72 | - $allowGzip = true; |
|
73 | - } |
|
64 | + // We only allow gzip in some cases |
|
65 | + if ($response instanceof BaseResponse) { |
|
66 | + $allowGzip = true; |
|
67 | + } |
|
68 | + if ($response instanceof JSONResponse) { |
|
69 | + $allowGzip = true; |
|
70 | + } |
|
71 | + if ($response instanceof TemplateResponse) { |
|
72 | + $allowGzip = true; |
|
73 | + } |
|
74 | 74 | |
75 | - if ($allowGzip) { |
|
76 | - $this->useGZip = true; |
|
77 | - $response->addHeader('Content-Encoding', 'gzip'); |
|
78 | - } |
|
75 | + if ($allowGzip) { |
|
76 | + $this->useGZip = true; |
|
77 | + $response->addHeader('Content-Encoding', 'gzip'); |
|
78 | + } |
|
79 | 79 | |
80 | - return $response; |
|
81 | - } |
|
80 | + return $response; |
|
81 | + } |
|
82 | 82 | |
83 | - public function beforeOutput($controller, $methodName, $output) { |
|
84 | - if (!$this->useGZip) { |
|
85 | - return $output; |
|
86 | - } |
|
83 | + public function beforeOutput($controller, $methodName, $output) { |
|
84 | + if (!$this->useGZip) { |
|
85 | + return $output; |
|
86 | + } |
|
87 | 87 | |
88 | - return gzencode($output); |
|
89 | - } |
|
88 | + return gzencode($output); |
|
89 | + } |
|
90 | 90 | } |