Skip to content

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

Merged
merged 7 commits into from
Jul 28, 2025

Conversation

Julien-Dochez
Copy link
Contributor

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

@Julien-Dochez Julien-Dochez requested a review from a team as a code owner July 25, 2025 21:59
@Julien-Dochez Julien-Dochez requested review from hamishwillee and removed request for a team July 25, 2025 21:59
@github-actions github-actions bot added Content:HTTP HTTP docs size/s [PR only] 6-50 LoC changed labels Jul 25, 2025
Julien-Dochez and others added 2 commits July 28, 2025 10:05
- 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>
Comment on lines 48 to 54
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 |
Copy link
Member

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:

Suggested change
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.

Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Member

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

Copy link
Collaborator

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)

Copy link
Contributor

github-actions bot commented Jul 28, 2025

Preview URLs

Flaws (3)

URL: /en-US/docs/Web/HTTP/Reference/Headers/Content-Length
Title: Content-Length header
Flaw count: 3

  • unknown:
    • No generic content config found
    • no blog root
    • no blog root

(comment last updated: 2025-07-28 03:48:32)

@hamishwillee hamishwillee requested a review from bsmth July 28, 2025 01:33
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
Copy link
Member

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.

@Josh-Cena
Copy link
Member

Brian is ooo for a few weeks. Happy to give you a rubberstamp.

Copy link
Collaborator

@hamishwillee hamishwillee left a 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 .

@hamishwillee hamishwillee merged commit 89835e4 into mdn:main Jul 28, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:HTTP HTTP docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content-Length should mention other HTTP versions
3 participants