From 19f4f89e4692ee8c25cfb6185c581cb6226b0711 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Mon, 26 Feb 2018 14:34:32 +0300 Subject: [PATCH] Fix #2752: Get rid of IndexError in aiohttp web server --- CHANGES/2752.bugfix | 1 + aiohttp/web_protocol.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 CHANGES/2752.bugfix diff --git a/CHANGES/2752.bugfix b/CHANGES/2752.bugfix new file mode 100644 index 00000000000..b53fe016fd1 --- /dev/null +++ b/CHANGES/2752.bugfix @@ -0,0 +1 @@ +Fix ``IndexError`` in HTTP request handling by server. \ No newline at end of file diff --git a/aiohttp/web_protocol.py b/aiohttp/web_protocol.py index 8b52de17ffb..0ecf4542bbd 100644 --- a/aiohttp/web_protocol.py +++ b/aiohttp/web_protocol.py @@ -244,12 +244,14 @@ def data_received(self, data): 500, exc)) self.close() else: - for (msg, payload) in messages: - self._request_count += 1 - self._messages.append((msg, payload)) - - if self._waiter: - self._waiter.set_result(None) + if messages: + # sometimes the parser returns no messages + for (msg, payload) in messages: + self._request_count += 1 + self._messages.append((msg, payload)) + + if self._waiter is not None: + self._waiter.set_result(None) self._upgraded = upgraded if upgraded and tail: