Skip to content

Commit

Permalink
Merge pull request #395 from danielnelson/fix-deflate-response
Browse files Browse the repository at this point in the history
Fix deflate compression when writing a chunked response
  • Loading branch information
asvetlov committed Jun 5, 2015
2 parents 1e4b2d6 + 6183351 commit 43f188c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
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

0 comments on commit 43f188c

Please sign in to comment.