forked from hyperium/hyper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(server): fix Content-Lenth/Transfer-Encoding inference
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.
- Loading branch information
Showing
5 changed files
with
164 additions
and
94 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
edition = "2018" |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.