StreamResponse use Transfer-Encoding: chunked for 204 responses #5106
Closed
Description
🐞
This server :
from aiohttp import web
async def hello(request):
return web.StreamResponse(status=204)
app = web.Application()
app.add_routes([web.get('/', hello)])
web.run_app(app)returns invalid HTTP responses:
% echo -ne 'GET / HTTP/1.1\r\n\r\n' | nc -i 1 127.0.0.1 8080
HTTP/1.1 204 No Content
Transfer-Encoding: chunked
Content-Type: application/octet-stream
Date: Fri, 23 Oct 2020 14:14:39 GMT
Server: Python/3.8 aiohttp/3.6.3
0
(i am using OSX, so netcat is the BSD variant, the -i 1 is not needed on linux)
The HTTP RFC specifies that a 204 response MUST NOT contain a body and is considered done after the first empty line after the headers.
Although I'm not exactly sure whether or not a 0\r\n\r\n body is consider an empty body or not when using Transfer-Encoding: chunked - so your call whether or not this should be fixed here.
The eventual bug for us is caused more by this issue https://trac.nginx.org/nginx/ticket/2066#ticket , which stacks with this one to crash our node clients.