Repository navigation
Handle empty HTTP/1 205 response framing - #1464
Conversation
pjfanning
left a comment
There was a problem hiding this comment.
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:
- No length now waits for the connection to close. Strictly, a 205 without
Content-LengthorTransfer-Encodingis close-delimited (RFC 9112 §6.3). But a server that sends a bareHTTP/1.1 205 Reset Content\r\n\r\nand 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. emitoverride on the hot path. Every parser output now goes through a pattern match with a check onpendingResetContentResponse. 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 inemit.drainParserat EOF. TheOutgoingConnectionBlueprintchange 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.- Docs. The paragraph in
http-model.mddescribes parser framing details that users don't need. I'd drop it.
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).
3a35c12 to
63c1a1a
Compare
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
63c1a1a to
2f88624
Compare
|
I rebased this onto |
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
2f88624 to
a9915c5
Compare
Motivation
A
205 Reset Contentresponse 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 publicallowsEntityproperty to make both decisions. Consequently, an ordinary empty chunked 205 leaves0\r\n\r\nin the buffer, where it is parsed as the next response's status line on a persistent connection.Modification
StatusCodes.ResetContent.allowsEntityor the public empty-entity invariant.Content-Length: 0, or with neitherContent-LengthnorTransfer-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-zeroContent-Lengthis rejected.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 withContent-Length: 0, an empty chunked body or no length headers, the next response on the same connection still parses.References