From: SamvanLeipsig Date: Thu, 1 Jul 2021 11:20:24 +0000 (+0200) Subject: Fix case-sensitivity for Content-Encoding: gzip. as per rfc7231 the Content-Encoding... X-Git-Tag: v6.2.0b1~42^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3041%2Fhead;p=thirdparty%2Ftornado.git Fix case-sensitivity for Content-Encoding: gzip. as per rfc7231 the Content-Encoding values are case-insensitive https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.2.1 --- diff --git a/tornado/http1connection.py b/tornado/http1connection.py index 72088d602..5ca916888 100644 --- a/tornado/http1connection.py +++ b/tornado/http1connection.py @@ -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. diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index 614dec7b8..58696e238 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -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):