Skip to content

Commit

Permalink
Do not hang on 206 Partial Content response with `Content-Encoding:…
Browse files Browse the repository at this point in the history
… gzip`
  • Loading branch information
Paulius Šileikis committed Jul 16, 2018
1 parent 5bbc255 commit 9862aa8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/3123.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not hang on `206 Partial Content` response with `Content-Encoding: gzip`
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Panagiotis Kolokotronis
Pankaj Pandey
Pau Freixes
Paul Colomiets
Paulius Šileikis
Paulus Schoutsen
Pavel Kamaev
Pawel Miech
Expand Down
2 changes: 1 addition & 1 deletion aiohttp/http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def feed_eof(self):

if chunk or self.size > 0:
self.out.feed_data(chunk, len(chunk))
if self.encoding != 'br' and not self.decompressor.eof:
if self.encoding == 'deflate' and not self.decompressor.eof:
raise ContentEncodingError('deflate')

self.out.feed_eof()
Expand Down
24 changes: 23 additions & 1 deletion tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ def test_feed_eof(self, stream):
assert [b'line'] == list(d for d, _ in buf._buffer)
assert buf._eof

def test_feed_eof_err(self, stream):
def test_feed_eof_err_deflate(self, stream):
buf = aiohttp.FlowControlDataQueue(stream)
dbuf = DeflateBuffer(buf, 'deflate')

Expand All @@ -913,6 +913,28 @@ def test_feed_eof_err(self, stream):
with pytest.raises(http_exceptions.ContentEncodingError):
dbuf.feed_eof()

def test_feed_eof_no_err_gzip(self, stream):
buf = aiohttp.FlowControlDataQueue(stream)
dbuf = DeflateBuffer(buf, 'gzip')

dbuf.decompressor = mock.Mock()
dbuf.decompressor.flush.return_value = b'line'
dbuf.decompressor.eof = False

dbuf.feed_eof()
assert [b'line'] == list(d for d, _ in buf._buffer)

def test_feed_eof_no_err_brotli(self, stream):
buf = aiohttp.FlowControlDataQueue(stream)
dbuf = DeflateBuffer(buf, 'br')

dbuf.decompressor = mock.Mock()
dbuf.decompressor.flush.return_value = b'line'
dbuf.decompressor.eof = False

dbuf.feed_eof()
assert [b'line'] == list(d for d, _ in buf._buffer)

def test_empty_body(self, stream):
buf = aiohttp.FlowControlDataQueue(stream)
dbuf = DeflateBuffer(buf, 'deflate')
Expand Down

0 comments on commit 9862aa8

Please sign in to comment.