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 requestpull/11139/merge
parent
909a06566e
commit
92aeef82ef
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue