]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Compress all text/* content types, not just a whitelist.
authorBen Darnell <ben@bendarnell.com>
Mon, 17 Feb 2014 04:59:17 +0000 (23:59 -0500)
committerBen Darnell <ben@bendarnell.com>
Mon, 17 Feb 2014 04:59:17 +0000 (23:59 -0500)
Closes #982.

tornado/web.py

index d3f260bdbd1a929e35fb883eed61ce1d25be809c..2d9908055914c00f2531916fb657b42942e8715f 100644 (file)
@@ -2299,16 +2299,20 @@ class GZipContentEncoding(OutputTransform):
 
     See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11
     """
-    CONTENT_TYPES = set([
-        "text/plain", "text/html", "text/css", "text/xml", "application/javascript",
-        "application/x-javascript", "application/xml", "application/atom+xml",
-        "text/javascript", "application/json", "application/xhtml+xml"])
+    # Whitelist of compressible mime types (in addition to any types
+    # beginning with "text/").
+    CONTENT_TYPES = set(["application/javascript", "application/x-javascript",
+                         "application/xml", "application/atom+xml",
+                         "application/json", "application/xhtml+xml"])
     MIN_LENGTH = 5
 
     def __init__(self, request):
         self._gzipping = request.supports_http_1_1() and \
             "gzip" in request.headers.get("Accept-Encoding", "")
 
+    def _compressible_type(self, ctype):
+        return ctype.startswith('text/') or ctype in self.CONTENT_TYPES
+
     def transform_first_chunk(self, status_code, headers, chunk, finishing):
         if 'Vary' in headers:
             headers['Vary'] += b', Accept-Encoding'
@@ -2316,7 +2320,7 @@ class GZipContentEncoding(OutputTransform):
             headers['Vary'] = b'Accept-Encoding'
         if self._gzipping:
             ctype = _unicode(headers.get("Content-Type", "")).split(";")[0]
-            self._gzipping = (ctype in self.CONTENT_TYPES) and \
+            self._gzipping = self._compressible_type(ctype) and \
                 (not finishing or len(chunk) >= self.MIN_LENGTH) and \
                 (finishing or "Content-Length" not in headers) and \
                 ("Content-Encoding" not in headers)