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

Fix deflate compression when writing a chunked response #395

Merged
merged 1 commit into from
Jun 5, 2015
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
3 changes: 2 additions & 1 deletion aiohttp/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,8 @@ def write(self, chunk, *,
if self.filter:
chunk = self.filter.send(chunk)
while chunk not in (EOF_MARKER, EOL_MARKER):
self.writer.send(chunk)
if chunk:
self.writer.send(chunk)
chunk = next(self.filter)
else:
if chunk is not EOF_MARKER:
Expand Down
12 changes: 9 additions & 3 deletions tests/test_http_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,9 @@ def test_write_payload_deflate_filter(self):
msg.write(b'data')
msg.write_eof()

content = b''.join([c[1][0] for c in list(write.mock_calls)])
chunks = [c[1][0] for c in list(write.mock_calls)]
self.assertTrue(all(chunks))
content = b''.join(chunks)
self.assertEqual(
self._COMPRESSED, content.split(b'\r\n\r\n', 1)[-1])

Expand All @@ -449,7 +451,9 @@ def test_write_payload_deflate_and_chunked(self):
msg.write(b'data')
msg.write_eof()

content = b''.join([c[1][0] for c in list(write.mock_calls)])
chunks = [c[1][0] for c in list(write.mock_calls)]
self.assertTrue(all(chunks))
content = b''.join(chunks)
self.assertEqual(
b'2\r\nKI\r\n2\r\n,I\r\n2\r\n\x04\x00\r\n0\r\n\r\n',
content.split(b'\r\n\r\n', 1)[-1])
Expand All @@ -466,7 +470,9 @@ def test_write_payload_chunked_and_deflate(self):
msg.write(b'data')
msg.write_eof()

content = b''.join([c[1][0] for c in list(write.mock_calls)])
chunks = [c[1][0] for c in list(write.mock_calls)]
self.assertTrue(all(chunks))
content = b''.join(chunks)
self.assertEqual(
self._COMPRESSED, content.split(b'\r\n\r\n', 1)[-1])

Expand Down