Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Content-Length and Transfer-Encoding #2432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jeddenlea
Copy link

Fixes #2427

still needs tests, and probably better naming of new functions!

@jeddenlea jeddenlea force-pushed the master branch 5 times, most recently from 800384f to 14c3680 Compare February 12, 2021 00:48
@jeddenlea jeddenlea force-pushed the master branch 2 times, most recently from a10ee64 to 7ddd943 Compare February 23, 2021 00:40
@jeddenlea jeddenlea marked this pull request as ready for review February 23, 2021 00:40
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problems with Content-Length and Transfer-Encoding
1 participant