From a24613da9cb4b209430b0c6309dcb6a636ac0374 Mon Sep 17 00:00:00 2001 From: Unrud Date: Sat, 21 May 2016 02:26:03 +0200 Subject: [PATCH] Compress answer The protocol uses verbose XML and compression reduces the size significantly. --- radicale/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/radicale/__init__.py b/radicale/__init__.py index 35ab75d..5251bfc 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -33,6 +33,7 @@ import socket import ssl import wsgiref.simple_server import re +import zlib from http import client from urllib.parse import unquote, urlparse @@ -314,6 +315,13 @@ class Application: if answer: self.logger.debug("Response content:\n%s" % answer, environ) answer = answer.encode(self.encoding) + accept_encoding = [ + encoding.strip() for encoding in + environ.get("HTTP_ACCEPT_ENCODING", "").split(",") + if encoding.strip()] + if "deflate" in accept_encoding: + answer = zlib.compress(answer) + headers["Content-Encoding"] = "deflate" headers["Content-Length"] = str(len(answer)) if self.configuration.has_section("headers"):