Skip to content

Commit

Permalink
[3.1] Call on_chunk_sent when write_eof is called with a valid chunk (G…
Browse files Browse the repository at this point in the history
…H-2911)

(cherry picked from commit 6a6ab7d)

Co-authored-by: Pau Freixes <[email protected]>
  • Loading branch information
pfreixes committed Apr 4, 2018
1 parent 98c7491 commit dc4f4ee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/2909.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Call on_chunk_sent when write_eof takes as a param the last chunk
3 changes: 3 additions & 0 deletions aiohttp/http_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions tests/test_http_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit dc4f4ee

Please sign in to comment.