Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit 98d9e5f

Browse files
authored
Merge pull request #367 from viranch/invalid-compression
Fix crash on getting unsupported content-encoding
2 parents 0ac3471 + 4f86b47 commit 98d9e5f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

hyper/http20/response.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ def __init__(self, headers, stream):
7979
# Stack Overflow answer for more:
8080
# http://stackoverflow.com/a/2695466/1401686
8181
for c in self.headers.get(b'content-encoding', []):
82-
self._decompressobj = decompressors.get(c)()
83-
break
82+
if c in decompressors:
83+
self._decompressobj = decompressors.get(c)()
84+
break
8485

8586
@property
8687
def trailers(self):

test/test_hyper.py

+9
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,15 @@ def test_response_transparently_decrypts_wrong_deflate(self):
11101110

11111111
assert resp.read() == b'this is test data'
11121112

1113+
def test_response_ignored_unsupported_compression(self):
1114+
headers = HTTPHeaderMap(
1115+
[(':status', '200'), ('content-encoding', 'invalid')]
1116+
)
1117+
body = b'this is test data'
1118+
resp = HTTP20Response(headers, DummyStream(body))
1119+
1120+
assert resp.read() == b'this is test data'
1121+
11131122
def test_response_calls_stream_close(self):
11141123
headers = HTTPHeaderMap([(':status', '200')])
11151124
stream = DummyStream('')

0 commit comments

Comments
 (0)