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 #758: Handle empty body with gzipped encoding #807

Merged
merged 1 commit into from
Feb 28, 2016
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 @@ -286,7 +286,8 @@ def __call__(self, out, buf):
length = 8

# payload decompression wrapper
if self.compression and self.message.compression:
if (self.response_with_body and
self.compression and self.message.compression):
out = DeflateBuffer(out, self.message.compression)

# payload parser
Expand Down
4 changes: 4 additions & 0 deletions aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@ def enable_compression(self, force=None):
# Backwards compatibility for when force was a bool <0.17.
if type(force) == bool:
force = ContentCoding.deflate if force else ContentCoding.identity
elif force is not None:
assert isinstance(force, ContentCoding), ("force should one of "
"None, bool or "
"ContentEncoding")

self._compression = True
self._compression_force = force
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ def post(self, path, **kwargs):
url = self._url + path
return self._session.post(url, **kwargs)

def delete(self, path, **kwargs):
while path.startswith('/'):
path = path[1:]
url = self._url + path
return self._session.delete(url)

def ws_connect(self, path, **kwargs):
while path.startswith('/'):
path = path[1:]
Expand Down
19 changes: 19 additions & 0 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,22 @@ def handler(request):
resp = yield from client.get('/', version=aiohttp.HttpVersion11)
assert resp.status == 200
resp.close()


@pytest.mark.run_loop
def test_204_with_gzipped_content_encoding(create_app_and_client):
@asyncio.coroutine
def handler(request):
resp = web.StreamResponse(status=204)
resp.content_length = 0
resp.content_type = 'application/json'
# resp.enable_compression(web.ContentCoding.gzip)
resp.headers['Content-Encoding'] = 'gzip'
yield from resp.prepare(request)
return resp

app, client = yield from create_app_and_client()
app.router.add_route('DELETE', '/', handler)
resp = yield from client.delete('/')
assert resp.status == 204
yield from resp.release()