Repository navigation
wsgi: Discard the response body for HEAD requests - #3830
Merged
Merged
Conversation
WSGIContainer passed whatever body the application returned to write_headers, but HTTP1Connection expects no content in a HEAD response. Any WSGI app that returns a body for HEAD and leaves it to the server to drop it (the issue was reported with Django) failed with "Tried to write more data than Content-Length", and the client saw a closed stream. Drop the body for HEAD the same way RequestHandler does, after the Content-Length has been computed from it. Fixes tornadoweb#2190 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2190.
WSGIContainerpasses whatever body the WSGI app returned straight towrite_headers(). For a HEAD requestHTTP1Connectionexpects no content, so an app that returns a body for HEAD and leaves it to the server to drop it (Django in the original report, or even thesimple_appexample from the docs) fails withHTTPOutputError: Tried to write more data than Content-Length, and the client just sees the stream close.Following the suggestion in the issue, this accepts and discards the body for HEAD, the same way
RequestHandler.flush()already does. The body is dropped afterContent-Lengthhas been filled in, so the HEAD response still carries the length a GET would.I added
test_headtowsgi_test.py; it fails on master and passes with this change. I also checked by hand that HEAD and GET requests alternate correctly on a single keep-alive connection.I used Claude Code to write this change.