Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andreas Bernacca · committed by Seth Michael Larson · parent 079ab33 · Browse files · 2 files+14 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−2 removed

  • tests:+9 added−0 removed
  • other:+5 added−2 removed

2 files+14 added−2 removed

modified:httpx/models.py+5 added-2 removed
778 unmodified lines
779 decoders: typing.List[Decoder] = []780 values = self.headers.getlist("content-encoding", split_commas=True)781 for value in values:782 value = value.strip().lower()783 try:783 decoder_cls = SUPPORTED_DECODERS[value]784 decoders.append(decoder_cls())784 decoder_cls = SUPPORTED_DECODERS[value]785 decoders.append(decoder_cls())786 except KeyError:787 continue788789 if len(decoders) == 1:790 self._decoder = decoders[0]791 elif len(decoders) > 1:
381 unmodified lines
modified:tests/test_decoders.py+9 added
84 unmodified lines
85 compressed_body = brotli.compress(body)[3:]86 with pytest.raises(httpx.exceptions.DecodingError):87 response = httpx.Response(200, headers=headers, content=compressed_body)88 response.content899091def test_invalid_content_encoding_header(header_value):92 headers = [(b"Content-Encoding", header_value)]93 body = b"test 123"9495 response = httpx.Response(200, headers=headers, content=body)9697 assert response.read() == body