Gzip all the things
This commit is contained in:
parent
9c5e7a9584
commit
1750b22e59
1 changed files with 11 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
"""This module provides WSGI application to serve the Home Assistant API."""
|
"""This module provides WSGI application to serve the Home Assistant API."""
|
||||||
import hmac
|
import hmac
|
||||||
|
import gzip
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
@ -258,7 +259,16 @@ class HomeAssistantWSGI(object):
|
||||||
adapter = self.url_map.bind_to_environ(request.environ)
|
adapter = self.url_map.bind_to_environ(request.environ)
|
||||||
try:
|
try:
|
||||||
endpoint, values = adapter.match()
|
endpoint, values = adapter.match()
|
||||||
return self.views[endpoint].handle_request(request, **values)
|
resp = self.views[endpoint].handle_request(request, **values)
|
||||||
|
|
||||||
|
if resp.is_streamed or 200 > resp.status_code >= 300 or \
|
||||||
|
'gzip' not in request.accept_encodings:
|
||||||
|
return resp
|
||||||
|
|
||||||
|
resp.headers.extend([('Content-Encoding', 'gzip'),
|
||||||
|
('Vary', 'Accept-Encoding')])
|
||||||
|
resp.data = gzip.compress(b''.join(resp.iter_encoded()))
|
||||||
|
return resp
|
||||||
except RequestRedirect as ex:
|
except RequestRedirect as ex:
|
||||||
return ex
|
return ex
|
||||||
except (BadRequest, NotFound, MethodNotAllowed,
|
except (BadRequest, NotFound, MethodNotAllowed,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue