]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Ignore Content-Encoding headers that are invalid (#196)
authorAndreas Bernacca <rinti@users.noreply.github.com>
Fri, 9 Aug 2019 02:33:55 +0000 (04:33 +0200)
committerSeth Michael Larson <sethmichaellarson@gmail.com>
Fri, 9 Aug 2019 02:33:55 +0000 (21:33 -0500)
httpx/models.py
tests/test_decoders.py

index 4b9bdc5d95b3d8744e889a9ecb0b1d8331022b6e..e7e7a57ae3a8a5eb4adebf2e3187316e0ce9c976 100644 (file)
@@ -780,8 +780,11 @@ class BaseResponse:
             values = self.headers.getlist("content-encoding", split_commas=True)
             for value in values:
                 value = value.strip().lower()
-                decoder_cls = SUPPORTED_DECODERS[value]
-                decoders.append(decoder_cls())
+                try:
+                    decoder_cls = SUPPORTED_DECODERS[value]
+                    decoders.append(decoder_cls())
+                except KeyError:
+                    continue
 
             if len(decoders) == 1:
                 self._decoder = decoders[0]
index 49247a9f442300d5136a772c080b7734bbadc58e..e292eb0662b5fb6449ea990257d39c659e7d0c43 100644 (file)
@@ -86,3 +86,12 @@ def test_decoding_errors(header_value):
     with pytest.raises(httpx.exceptions.DecodingError):
         response = httpx.Response(200, headers=headers, content=compressed_body)
         response.content
+
+
+def test_invalid_content_encoding_header(header_value):
+    headers = [(b"Content-Encoding", header_value)]
+    body = b"test 123"
+
+    response = httpx.Response(200, headers=headers, content=body)
+
+    assert response.read() == body