Skip to content

Handle empty HTTP/1 205 response framing - #1464

Merged
pjfanning merged 3 commits into
apache:mainfrom
He-Pin:fix/http1-205-empty-framing
Nov 19, 2026
Merged

pjfanning merged 3 commits into
apache:mainfrom
He-Pin:fix/http1-205-empty-framing

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Motivation

A 205 Reset Content response must not contain content, but it is not one of the responses whose HTTP/1 message framing ends immediately after the headers. The client currently uses the public allowsEntity property to make both decisions. Consequently, an ordinary empty chunked 205 leaves 0\r\n\r\n in the buffer, where it is parsed as the next response's status line on a persistent connection.

Modification

  • Consume 205 message framing without changing StatusCodes.ResetContent.allowsEntity or the public empty-entity invariant.
  • For an empty chunked 205, defer the empty response until the terminating chunk has been consumed. A non-empty chunk is rejected rather than exposed as an entity.
  • A 205 with Content-Length: 0, or with neither Content-Length nor Transfer-Encoding, is delivered immediately as an empty response, as before. Strictly the latter is close-delimited (RFC 9112 §6.3), but it cannot carry content, so delivering it immediately avoids stalling the client when a server keeps the connection open. A non-zero Content-Length is rejected.
  • Preserve HEAD/CONNECT handling and the shared chunk parser.
  • Add focused parser and connection-level coverage.

Result

Legal empty 205 responses work with persistent connections while remaining known-empty to applications. The chunked regression test fails on the previous implementation.

Tests

  • ResponseParserSpec (CRLF/LF): an empty chunked 205 is emitted only after its terminating chunk, and a 205 without length headers is emitted immediately, for both GET and HEAD.
  • LowLevelOutgoingConnectionSpec: after a 205 with Content-Length: 0, an empty chunked body or no length headers, the next response on the same connection still parses.
  • CI passes.

References

@pjfanning pjfanning added this to the 2.1.0 milestone Nov 15, 2026

@pjfanning pjfanning left a comment

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.

Thanks. The chunked case is a real bug: treating a 205 like a 204 leaves 0\r\n\r\n in the buffer, where it gets parsed as the next response's status line. Consuming the empty chunked framing while keeping the public entity known-empty is the right fix. A few points:

  1. No length now waits for the connection to close. Strictly, a 205 without Content-Length or Transfer-Encoding is close-delimited (RFC 9112 §6.3). But a server that sends a bare HTTP/1.1 205 Reset Content\r\n\r\n and keeps the connection open is non-compliant yet plausible, and with this change the client holds that response until the connection closes or times out. Before, it was delivered immediately. Since a 205 can't carry content anyway, delivering it immediately (as before) works either way: if the server closes, nothing is lost, and if it keeps the connection alive and sends the next response, that response parses correctly. I'd keep the deferral for the chunked case only.
  2. emit override on the hot path. Every parser output now goes through a pattern match with a check on pendingResetContentResponse. It's cheap, but it puts 205-specific state into the general emit path. If point 1 is adopted, only the chunked case needs deferring, which might fit inside the chunk-parsing path rather than in emit.
  3. drainParser at EOF. The OutgoingConnectionBlueprint change drains all parser output at upstream finish, not just the next element, for every response. That's probably more correct in general, but it changes EOF handling for every response, not just 205. A test that doesn't involve 205 (e.g. a close-delimited 200 followed by EOF) would show nothing else changed.
  4. Docs. The paragraph in http-model.md describes parser framing details that users don't need. I'd drop it.

He-Pin added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
Motivation:
A reset-content response must expose no entity, while HTTP/1 message framing still applies.

Modification:
Keep the existing empty-response framing change and tests. Remove the protocol implementation detail from the user guide, retaining the anchor.

Result:
The guide remains focused on the HTTP model. Runtime behavior is unchanged by this follow-up.

Tests:
Not run for the documentation-only follow-up. Existing runtime and test files
match the previous PR head. git diff --check passed.

References:
Refs apache#1464. RFC 9110 section 15.3.6, RFC 9112 section 6.3 and Netty 72a216625f16 (historical comparison).
@He-Pin
He-Pin force-pushed the fix/http1-205-empty-framing branch from 3a35c12 to 63c1a1a Compare November 17, 2026 15:34
pjfanning pushed a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
Motivation:
A reset-content response must expose no entity, while HTTP/1 message framing still applies.

Modification:
Keep the existing empty-response framing change and tests. Remove the protocol implementation detail from the user guide, retaining the anchor.

Result:
The guide remains focused on the HTTP model. Runtime behavior is unchanged by this follow-up.

Tests:
Not run for the documentation-only follow-up. Existing runtime and test files
match the previous PR head. git diff --check passed.

References:
Refs apache#1464. RFC 9110 section 15.3.6, RFC 9112 section 6.3 and Netty 72a216625f16 (historical comparison).
pjfanning added a commit to He-Pin/incubator-pekko-http that referenced this pull request Nov 17, 2026
Motivation:
A 205 without Content-Length or Transfer-Encoding is strictly
close-delimited, so the change held the response until the connection
closed. A server that sends a bare 205 and keeps the connection open would
then stall the client, where it previously got the response immediately.

Modification:
Treat a 205 without length headers as an empty response straight away, as
before, and keep deferring only the empty chunked case. Remove the
close-delimited handling and revert the EOF drain in
OutgoingConnectionBlueprint, which was only needed for it. Replace the
EOF-based tests with one showing the next response on a persistent
connection still parses.

Result:
Empty chunked 205 framing is still consumed, while 205 responses without
length headers no longer wait for the connection to close.

Tests:
- sbt "http-core/testOnly ...ResponseParserCRLFSpec ...ResponseParserLFSpec ...LowLevelOutgoingConnectionSpec ...ResponseParsingMergeSpec": 106 passed

References:
Refs apache#1464 review
@pjfanning
pjfanning force-pushed the fix/http1-205-empty-framing branch from 63c1a1a to 2f88624 Compare November 17, 2026 18:41
@pjfanning

Copy link
Copy Markdown
Member

I rebased this onto main and pushed a separate commit (2f88624). A 205 without Content-Length or Transfer-Encoding is now delivered immediately as an empty response, as before, so a server that keeps the connection open doesn't stall the client. The deferral is kept only for the empty chunked case. That made the EOF drain in OutgoingConnectionBlueprint unnecessary, so I reverted it. The close-delimited tests are replaced by one showing that the next response on a persistent connection still parses. Feel free to revert anything you don't agree with.

He-Pin and others added 3 commits November 18, 2026 21:57
Motivation:
A reset-content response must expose no entity, while HTTP/1 message framing still applies.

Modification:
Keep the existing empty-response framing change and tests. Remove the protocol implementation detail from the user guide, retaining the anchor.

Result:
The guide remains focused on the HTTP model. Runtime behavior is unchanged by this follow-up.

Tests:
Not run for the documentation-only follow-up. Existing runtime and test files
match the previous PR head. git diff --check passed.

References:
Refs apache#1464. RFC 9110 section 15.3.6, RFC 9112 section 6.3 and Netty 72a216625f16 (historical comparison).
Motivation:
A 205 without Content-Length or Transfer-Encoding is strictly
close-delimited, so the change held the response until the connection
closed. A server that sends a bare 205 and keeps the connection open would
then stall the client, where it previously got the response immediately.

Modification:
Treat a 205 without length headers as an empty response straight away, as
before, and keep deferring only the empty chunked case. Remove the
close-delimited handling and revert the EOF drain in
OutgoingConnectionBlueprint, which was only needed for it. Replace the
EOF-based tests with one showing the next response on a persistent
connection still parses.

Result:
Empty chunked 205 framing is still consumed, while 205 responses without
length headers no longer wait for the connection to close.

Tests:
- sbt "http-core/testOnly ...ResponseParserCRLFSpec ...ResponseParserLFSpec ...LowLevelOutgoingConnectionSpec ...ResponseParsingMergeSpec": 106 passed

References:
Refs apache#1464 review
Motivation:
The docs paragraph was dropped during review, but a blank line it added
before the HttpEntity heading was left behind.

Modification:
Restore http-model.md to its state on main.

Result:
The PR no longer touches the docs.

Tests:
- Not run - docs only

References:
Refs apache#1464
@pjfanning
pjfanning force-pushed the fix/http1-205-empty-framing branch from 2f88624 to a9915c5 Compare November 18, 2026 20:57

@pjfanning pjfanning left a comment

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.

LGTM

@pjfanning
pjfanning merged commit 9ed11bc into apache:main Nov 19, 2026
6 checks passed
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.

2 participants