From 6191e5a16b19cbd5aba66887b08d4f24ebcee582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA?= Date: Sat, 5 Jan 2019 00:42:43 +0500 Subject: [PATCH] Fix handling of chunked+gzipped response when first chunk does not give uncompressed data (#3477) --- aiohttp/streams.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/aiohttp/streams.py b/aiohttp/streams.py index 9dd08794fa3..cdd6801fc81 100644 --- a/aiohttp/streams.py +++ b/aiohttp/streams.py @@ -254,15 +254,23 @@ def end_http_chunk_receiving(self) -> None: if self._http_chunk_splits is None: raise RuntimeError("Called end_chunk_receiving without calling " "begin_chunk_receiving first") - if not self._http_chunk_splits or \ - self._http_chunk_splits[-1] != self.total_bytes: - self._http_chunk_splits.append(self.total_bytes) - # wake up readchunk when end of http chunk received - waiter = self._waiter - if waiter is not None: - self._waiter = None - set_result(waiter, False) + current_position = self._http_chunk_splits[-1] if self._http_chunk_splits else 0 + + if self.total_bytes == current_position: + # Note, when chunked + gzip is used, we can receive some chunk + # of compressed data, but that data may not be enough for gzip FSM to yield + # any uncompressed data. That's why current position may not change after + # receiving a chunk. + return + + self._http_chunk_splits.append(self.total_bytes) + + # wake up readchunk when end of http chunk received + waiter = self._waiter + if waiter is not None: + self._waiter = None + set_result(waiter, False) async def _wait(self, func_name: str) -> None: # StreamReader uses a future to link the protocol feed_data() method