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

Call on_chunk_sent when write_eof is called with a valid chunk #2911

Merged
merged 1 commit into from
Apr 4, 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 @@ -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