From 92aeef82ef26f16512e55bbaf95930d79124721c Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Sun, 18 Feb 2018 06:32:08 +0100 Subject: [PATCH] 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 --- homeassistant/components/http/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 6472846cd13..450d802e408 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -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):