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)