Ignore Content-Encoding headers that are invalid (#196)

This commit is contained in:
Andreas Bernacca 2019-08-09 04:33:55 +02:00 committed by Seth Michael Larson
parent 079ab33c12
commit de91fdfa16
2 changed files with 14 additions and 2 deletions

View 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]

View 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