Closed dchaplinsky closed 2 weeks ago
from aiohttp import web
async def enable_compression(request, response):
# Only enable compression if response has a body
if response.body is not None:
response.enable_compression()
async def remove_server_header(request, response):
response.headers.pop('Server', None)
async def whatever(request):
raise web.HTTPNoContent()
app = web.Application()
app.on_response_prepare.append(enable_compression)
app.on_response_prepare.append(remove_server_header)
app.router.add_get('/', whatever)
if __name__ == '__main__':
web.run_app(app)
I suspect this assert should be changed to be part of the if statement: https://github.com/aio-libs/aiohttp/blob/0ec65c0f4dc08d027f659256b09ae9cff10ab404/aiohttp/web_response.py#L707
If someone can add a test that reproduces the issue with a 204 response, then we can fix that.
Long story short
I've enabled gzip compression like that but it throws exception on 204 responses
Expected behaviour
Do not throw exception if body is absent
Actual behaviour
Steps to reproduce
but when I do
exception above happens
Your environment
python 3.6.5 aiohttp (both) 3.3.2 MacOS 10.13.5 (17F77)