-
Notifications
You must be signed in to change notification settings - Fork 22.8k
docs (content-length) : Add HTTP version comparison #40534
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
Conversation
- Add comparison between HTTP/1.1 and HTTP/2 behaviors - Addresses issue mdn#36681
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
The handling of `Content-Length` differs between HTTP versions: | ||
|
||
| Feature | HTTP/1.1 | HTTP/2 | | ||
| --------------- | -------------------------------- | ------------------------- | | ||
| Required | Yes (for persistent connections) | Optional | | ||
| Primary purpose | Frame body size | Backward compatibility | | ||
| Alternatives | `Transfer-Encoding` | Inferred from DATA frames | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to point out that this is very low information density and very un-MDN because you could have been a single sentence in the intro:
The handling of `Content-Length` differs between HTTP versions: | |
| Feature | HTTP/1.1 | HTTP/2 | | |
| --------------- | -------------------------------- | ------------------------- | | |
| Required | Yes (for persistent connections) | Optional | | |
| Primary purpose | Frame body size | Backward compatibility | | |
| Alternatives | `Transfer-Encoding` | Inferred from DATA frames | | |
`Content-Length` was required in HTTP/1.1 for persistent connections to indicate the frame body size. It became optional in HTTP/2 because the size can now be inferred from DATA frames, and this header is only kept for compatibility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Josh-Cena I was writing my response at the same time as you - #40534 (comment) - took me a lot longer
Similar feeling except that I thought (something like) this was useful to add in the introduction too:
Content-Length
is limited in that the message size must be known up front, before sending the headers, which is a problem when content is dynamically generated or streamed. Transfer-Encoding: chunked allows the content to be sent out in parts as its size is calculated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So maybe we combine those two approaches in the intro?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes let's go with the wording you would prefer; I'm just paraphrasing here and you would know better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool. We agree on the main point of "MDN style". I lean towards #40534 (comment)
Preview URLs Flaws (3)URL:
(comment last updated: 2025-07-28 03:48:32) |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@@ -43,6 +43,18 @@ Content-Length: <length> | |||
- `<length>` | |||
- : The length in octets. | |||
|
|||
## HTTP version comparison |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I don't like ad-hoc H2 headings, would prefer if you change it to "description" or just put this in the intro.
Co-authored-by: Joshua Chen <[email protected]>
Brian is ooo for a few weeks. Happy to give you a rubberstamp. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Josh-Cena and @Julien-Dochez .
Description
Added a comparison table clarifying 'Content-Length' header behavior differences between HTTP/1.1 and HTTP/2.
Motivation
I made this simple change because it helps resolve confusion in a simple way. Developers may use this information to avoid unecessary header usage.
Additional details
https://httpwg.org/specs/rfc9113.html#rfc.section.8.1
Related issues and pull requests
Fixes #36681