Repository navigation
modify headers and body in place - #3335
Merged
Merged
Conversation
davidism
force-pushed
the
apply-status
branch
from
October 22, 2026 20:11
3901ae0 to
5b68c73
Compare
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.
closes #3320, related to #3281
Added
apply_status(mirroringapply_conditionsandapply_range) that modifies the headers and body based on the status.apply_conditionsandget_wsgi_responsecall it automatically.get_wsgi_headersandget_app_iterare deprecated.Despite #3281 wanting to pass
requestinstead ofenvironwhere possible, I decided to keepenvironforget_wsgi_response. It's almost always from__call__(environ, start_response), where we can't change that signature because its part of WSGI. Constructing a request there just for this would be sort of pointless, although it's not expensive. We can do it later if we want.Also decided not to pass
request(orenviron) toapply_status. First, it would require constructing a request fromget_wsgi_response, just discussed why not that. Second, no adjustments currently depend on the request, only "don't send a body on HEAD".Decided "don't send a body on HEAD" shouldn't modify the body in place, because then it would truly make caching responses useless, as it would always break a simple reused GET response automatically.
The 205 status clears
content-lengthand body, like 1XX, 204, and 304. This seems to have been overlooked and never reported, but might as well be consistent.set_datacalls the existing iterable'sclosemethod. This was missed in #3325Inspired by Quart,
make_sequencewill join all items into one bytes value and callset_data, which also setscontent_length. PEP 3333 says this is the preferred way to return simple responses, len > 1 iterators are meant for streaming. Unlike Quart, len > 1 sequences are left as-is, only non-sequences are converted, which matches existing behavior.freezeis deprecated. Added a new docs section explaining why responses can't be reused in general._ensure_sequencemutableparameter is deprecated. This was missed in #3325Updated docstrings. Clarified that
closeandcall_on_closeare not called ifdirect_passthroughis enabled.