Enable compression when sending json to client (#11165)

* Enable compression when sending json to client

Make server compress json content when transmitting to client. Json is quite verbose and compresses well.

A real world example is history_graph requested data for in my case 4 temperature sensors updating every half a second for a graph over 10 days lead to 6MB json which compressed to 200KB using deflate compression.

* Rename variable to request

* Name the variable response instead of request
pull/11139/merge
Joakim Plate 2018-02-18 06:32:08 +01:00 committed by Paulus Schoutsen
parent 909a06566e
commit 92aeef82ef
1 changed files with 3 additions and 1 deletions

View File

@ -340,9 +340,11 @@ class HomeAssistantView(object):
"""Return a JSON response."""
msg = json.dumps(
result, sort_keys=True, cls=rem.JSONEncoder).encode('UTF-8')
return web.Response(
response = web.Response(
body=msg, content_type=CONTENT_TYPE_JSON, status=status_code,
headers=headers)
response.enable_compression()
return response
def json_message(self, message, status_code=200, message_code=None,
headers=None):