Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 6a6ab7d and c5d399 to 3.1 #2915

Merged
merged 2 commits into from
Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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