Kaynağa Gözat

Compress answer

The protocol uses verbose XML and compression reduces the size significantly.
Unrud 9 yıl önce
ebeveyn
işleme
a24613da9c
1 değiştirilmiş dosya ile 8 ekleme ve 0 silme
  1. 8 0
      radicale/__init__.py

+ 8 - 0
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"):