Ignore Content-Encoding headers that are invalid (#196)
This commit is contained in:
parent
079ab33c12
commit
de91fdfa16
@ -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]
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user