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

Commit

Permalink
Merge pull request #367 from viranch/invalid-compression
Browse files Browse the repository at this point in the history
Fix crash on getting unsupported content-encoding
  • Loading branch information
Lukasa authored Nov 29, 2017
2 parents 0ac3471 + 4f86b47 commit 98d9e5f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 3 additions & 2 deletions hyper/http20/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ def __init__(self, headers, stream):
# Stack Overflow answer for more:
# http://stackoverflow.com/a/2695466/1401686
for c in self.headers.get(b'content-encoding', []):
self._decompressobj = decompressors.get(c)()
break
if c in decompressors:
self._decompressobj = decompressors.get(c)()
break

@property
def trailers(self):
Expand Down
9 changes: 9 additions & 0 deletions test/test_hyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,15 @@ def test_response_transparently_decrypts_wrong_deflate(self):

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

def test_response_ignored_unsupported_compression(self):
headers = HTTPHeaderMap(
[(':status', '200'), ('content-encoding', 'invalid')]
)
body = b'this is test data'
resp = HTTP20Response(headers, DummyStream(body))

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

def test_response_calls_stream_close(self):
headers = HTTPHeaderMap([(':status', '200')])
stream = DummyStream('')
Expand Down

0 comments on commit 98d9e5f

Please sign in to comment.