Fix Content-Length and Transfer-Encoding#2432
Open
jeddenlea wants to merge 1 commit intohyperium:masterfrom
Open
Fix Content-Length and Transfer-Encoding#2432jeddenlea wants to merge 1 commit intohyperium:masterfrom
jeddenlea wants to merge 1 commit intohyperium:masterfrom
Conversation
3 tasks
800384f to
14c3680
Compare
a10ee64 to
7ddd943
Compare
Fixes hyperium#2427 204s must never have either Content-Length or Transfer-Encoding headers. Nor should any 1xx response. Nor should any 2xx response made to a CONNECT request. On the other hand, any other kind of response may have either a Content-Length or Transfer-Encoding header. This includes 304s in general, and any response made to a HEAD request. In those of those cases, the headers should match what would have been sent with a normal response. The trick then is to ensure that such headers are not mis-inferred. When responding to a HEAD request, a service may reasonably opt out of computing the full response, and thus may not know how large it would be. To add automatically add `Content-Length: 0` would be a mistake. As Body::empty() seems to be the defacto "no response" Body, it shall be used as such. If a service responds to a HEAD request, or to a conditional GET request with a 304, it may specify Body::empty() as the body, and no Content-Length or Transfer-Encoding header will be added. In all other cases when a Content-Length header is required for HTTP message framing, `Content-Length: 0` will be still automatically added. Body::from("") on the other hand will now implie a specific empty Body. It will continue to imply `Content-Length: 0` in all cases, now including a 304 response. Either Content-Length or Transfer-Encoding may be added explicitly as headers for either HEAD requests or 304 responses.
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 #2427
still needs tests, and probably better naming of new functions!