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

StreamResponse use Transfer-Encoding: chunked for 204 responses #5106

Closed
arthurdarcet opened this issue Oct 23, 2020 · 2 comments
Closed

StreamResponse use Transfer-Encoding: chunked for 204 responses #5106

arthurdarcet opened this issue Oct 23, 2020 · 2 comments
Labels

Comments

@arthurdarcet
Copy link
Contributor

🐞
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.

@asvetlov
Copy link
Member

Ok, let's not send empty body for 204 (and drop Content-Type with Transfer-Encoding headers).
IIRC we already handle such cases on the client.

Would you prepare a patch?

@arthurdarcet
Copy link
Contributor Author

perfect, thanks @derlih !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants