Respect pre-computed content-length for HEAD responses - #353
Merged
Conversation
mtrudel
reviewed
May 13, 2024
Owner
|
Thanks for the PR! Left you some refactoring suggestions. We'll also need a test to cover this for both H1 and H2. |
meeq
commented
May 13, 2024
meeq
commented
May 14, 2024
mtrudel
approved these changes
May 15, 2024
mtrudel
left a comment
Owner
There was a problem hiding this comment.
One minor typo otherwise this is good to go!
Co-authored-by: Mat Trudel <mat@geeky.net>
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.
I have an application that streams extremely large payloads. Due to reasons beyond my control, HEAD requests must respond with HTTP status 200, so my Plug handler sends with:
However,
Bandit.Headers.add_content_length/3replaces my application's "content-length" header withcontent-length: 0.As it stands the only way for me to set "content-length" on a HEAD 200 response seems to be to either wastefully render the full response or allocate a body of "content-length"-size and pass it into
send_resp, but this is not practical or efficient. It also seems to violate the spirit of RFC9110 § 9.3.2:This patch introduces a simple, reasonably-safe heuristic to preserve the application's intent: if a HEAD response handler sets the content-length response header, treat it as the size of the body that would have been sent; RFC9110 §8.6: