From 2e372cdf4b696a9b6dd1bd25accb183ab4d574c9 Mon Sep 17 00:00:00 2001 From: Pau Freixes Date: Wed, 4 Apr 2018 06:54:33 +0200 Subject: [PATCH] Call on_chunk_sent when write_eof is called with a valid chunk --- CHANGES/2909.bugfix | 1 + aiohttp/http_writer.py | 3 +++ tests/test_http_writer.py | 12 ++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 CHANGES/2909.bugfix diff --git a/CHANGES/2909.bugfix b/CHANGES/2909.bugfix new file mode 100644 index 00000000000..617f44d6057 --- /dev/null +++ b/CHANGES/2909.bugfix @@ -0,0 +1 @@ +Call on_chunk_sent when write_eof takes as a param the last chunk diff --git a/aiohttp/http_writer.py b/aiohttp/http_writer.py index bc7201da1aa..9d04a429d48 100644 --- a/aiohttp/http_writer.py +++ b/aiohttp/http_writer.py @@ -122,6 +122,9 @@ async def write_eof(self, chunk=b''): chunk = b'0\r\n\r\n' if chunk: + if self._on_chunk_sent is not None: + await self._on_chunk_sent(chunk) + self._write(chunk) await self.drain() diff --git a/tests/test_http_writer.py b/tests/test_http_writer.py index 47d41ef3984..7f9d17dea34 100644 --- a/tests/test_http_writer.py +++ b/tests/test_http_writer.py @@ -171,6 +171,18 @@ async def test_write_calls_callback(protocol, transport, loop): assert on_chunk_sent.call_args == mock.call(chunk) +async def test_write_eof_calls_callback(protocol, transport, loop): + on_chunk_sent = make_mocked_coro() + msg = http.StreamWriter( + protocol, transport, loop, + on_chunk_sent=on_chunk_sent + ) + chunk = b'1' + await msg.write_eof(chunk=chunk) + assert on_chunk_sent.called + assert on_chunk_sent.call_args == mock.call(chunk) + + async def test_write_to_closing_transport(protocol, transport, loop): msg = http.StreamWriter(protocol, transport, loop)