]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix case-sensitivity for Content-Encoding: gzip. as per rfc7231 the Content-Encoding... 3041/head
authorSamvanLeipsig <s.am@live.nl>
Thu, 1 Jul 2021 11:20:24 +0000 (13:20 +0200)
committerSamvanLeipsig <s.am@live.nl>
Thu, 1 Jul 2021 11:20:24 +0000 (13:20 +0200)
tornado/http1connection.py
tornado/test/httpserver_test.py

index 72088d6023b0b55232351248e72d5915667bfb9c..5ca91688878b1a2d9f811497dbc0920796d70826 100644 (file)
@@ -718,7 +718,7 @@ class _GzipMessageDelegate(httputil.HTTPMessageDelegate):
         start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
         headers: httputil.HTTPHeaders,
     ) -> Optional[Awaitable[None]]:
-        if headers.get("Content-Encoding") == "gzip":
+        if headers.get("Content-Encoding", "").lower() == "gzip":
             self._decompressor = GzipDecompressor()
             # Downstream delegates will only see uncompressed data,
             # so rename the content-encoding header.
index 614dec7b8fb76398e7b3a19915f02284593edc94..58696e238e5756b954eb0f539bdc9676902e7b7d 100644 (file)
@@ -1000,6 +1000,21 @@ class GzipTest(GzipBaseTest, AsyncHTTPTestCase):
         response = self.post_gzip("foo=bar")
         self.assertEqual(json_decode(response.body), {u"foo": [u"bar"]})
 
+    def test_gzip_case_insensitive(self):
+        # https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.2.1
+        bytesio = BytesIO()
+        gzip_file = gzip.GzipFile(mode="w", fileobj=bytesio)
+        gzip_file.write(utf8("foo=bar"))
+        gzip_file.close()
+        compressed_body = bytesio.getvalue()
+        response = self.fetch(
+            "/",
+            method="POST",
+            body=compressed_body,
+            headers={"Content-Encoding": "GZIP"},
+        )
+        self.assertEqual(json_decode(response.body), {u"foo": [u"bar"]})
+
 
 class GzipUnsupportedTest(GzipBaseTest, AsyncHTTPTestCase):
     def test_gzip_unsupported(self):