Skip to content

Commit

Permalink
Backport 6a6ab7d and c5d399 to 3.1 (#2915)
Browse files Browse the repository at this point in the history
* Call on_chunk_sent when write_eof is called with a valid chunk (#2911)

(cherry picked from commit 6a6ab7d)

* Amends 4ce3c4a sending the chunk signal by write_eof equal than write (#2913)

(cherry picked from commit c5d3999)
  • Loading branch information
pfreixes authored Apr 5, 2018
1 parent 98c7491 commit db7dcb8
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 @@ -105,6 +105,9 @@ async def write_eof(self, chunk=b''):
if self._eof:
return

if chunk and self._on_chunk_sent is not None:
await self._on_chunk_sent(chunk)

if self._compress:
if chunk:
chunk = self._compress.compress(chunk)
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 db7dcb8

Please sign in to comment.