Skip to content

Strip Transfer-Encoding when Content-Length is present in HTTPEncoder#3583

Merged
fabianfett merged 4 commits intoapple:mainfrom
fabianfett:ff-fix-content-length-and-transfer-encoding
May 6, 2026
Merged

Strip Transfer-Encoding when Content-Length is present in HTTPEncoder#3583
fabianfett merged 4 commits intoapple:mainfrom
fabianfett:ff-fix-content-length-and-transfer-encoding

Conversation

@fabianfett
Copy link
Copy Markdown
Member

Strip Transfer-Encoding when Content-Length is present in HTTPEncoder

Motivation

When correctlyFrameTransportHeaders() detected a Content-Length header, it returned .contentLength without removing any existing Transfer-Encoding header.

Changes

  • Remove Transfer-Encoding header, if a Content-Length header is present

Result

NIO sends either a Content-Length header or a Transfer-Encoding header, but not both.

### Motivation

When correctlyFrameTransportHeaders() detected a Content-Length header, it returned .contentLength without removing any existing Transfer-Encoding header.

### Changes

- Remove Transfer-Encoding headers, if a Content-Length header is present

### Result

NIO sends either a `Content-Length` header or a `Transfer-Encoding` header, but not both.
@fabianfett fabianfett requested a review from Lukasa April 30, 2026 13:49
@fabianfett fabianfett added the 🔨 semver/patch No public API change. label Apr 30, 2026
@fabianfett fabianfett requested a review from glbrntt April 30, 2026 13:50
"1000_getHandlers": 8050,
"1000_getHandlers_sync": 37,
"1000_reqs_1_conn": 26350,
"1000_reqs_1_conn": 27400,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we are running into a cow now.

@fabianfett fabianfett enabled auto-merge (squash) May 6, 2026 10:13
@fabianfett fabianfett merged commit 37e191d into apple:main May 6, 2026
52 of 55 checks passed
@fabianfett fabianfett deleted the ff-fix-content-length-and-transfer-encoding branch May 6, 2026 10:57
return .neither
case .yes:
if headers.contains(name: "content-length") {
headers.remove(name: "transfer-encoding")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we trying to fix up illegal HTTP? Originally (as shown by the crash tests) the idea was that this is "programmer error". Kinda defensible but also maybe not super helpful for proxy authors.

But now we're trying to fix up broken HTTP? Why don't we reject using an error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants