Repository navigation
fix(mux-h2): add no Transfer-Encoding to a response without a body - #1778
Merged
Merged
Conversation
FlorentinDUBOIS
force-pushed
the
fix/h2-to-h1-bodiless-no-transfer-encoding
branch
2 times, most recently
from
October 2, 2026 00:01
689bf83 to
75c899c
Compare
When an H2 backend sent a header section without END_STREAM and without content-length, pkawa::handle_header added Transfer-Encoding: chunked and framed the response chunked for an H1 client, including for a 1xx, a 204, a 304 and a response to HEAD, which have no content by definition (RFC 9110 section 6.4.1). RFC 9112 section 6.1 forbids the field in a 1xx or 204, and a 1xx never completed, so an H1 client read a chunked 103 and never the final response. Such a response now gains no framing. A 1xx is complete at its head and the final response follows on the same stream. A 204, a 304 or a response to HEAD stays open until the backend ends its stream (RFC 9113 sections 5.1, 8.1), and that END_STREAM reaches an H2 client. Marked complete at its head, as a response to HEAD already was, the client stream was retired without END_STREAM and the backend stream reset with its trailer HEADERS in flight, which the closed-stream check answered with GOAWAY(STREAM_CLOSED) for the whole backend connection. A content-length is removed from a 1xx or a 204, where a server MUST NOT send it, and kept on a 304 or a response to HEAD (RFC 9110 section 8.6). A :status 101, which HTTP/2 does not support (RFC 9113 section 8.6), is a stream error (PROTOCOL_ERROR) answered 502. Closes #1776 Signed-off-by: Florentin Dubois <[email protected]>
FlorentinDUBOIS
force-pushed
the
fix/h2-to-h1-bodiless-no-transfer-encoding
branch
from
October 2, 2026 02:07
75c899c to
cafeec5
Compare
FlorentinDUBOIS
added a commit
that referenced
this pull request
Oct 2, 2026
…HEAD response's DATA (#1775) A response to HEAD, a 204 or a 304 has no content (RFC 9110 §6.4.1), but `ConnectionH2::handle_data_frame` forwarded a DATA payload on it. An H1 client read it after the head as the start of the next response, and an H2 client received it as DATA. - 204 and 304 cannot carry content (RFC 9110 §15.3.5, §15.4.5; RFC 9113 §8.1.1). The backend stream is reset with PROTOCOL_ERROR before the payload is queued, counted in the new `h2.bodiless_response_data_reset`. An H1 client that was already sent the head sees the connection close; one that was not gets a 502. - A response to HEAD only SHOULD NOT carry content (RFC 9110 §9.3.2). Its windows are credited, and its payload is never queued and is dropped from the end of the stream buffer. If the payload were kept in the buffer, it would only be freed when the frontend consumes a queued block, and nothing refers to it. A payload larger than the buffer would then stop the backend connection from being read before END_STREAM, stalling every stream on that connection. With #1778, such a backend stream stays linked until its END_STREAM, so its DATA reaches these branches whether it arrives with the head or later. Known limitation: after the PROTOCOL_ERROR reset of a 204 or a 304, a trailer HEADERS frame the backend had already sent on that stream still triggers a GOAWAY that ends every stream of the backend connection. This lasts until #1784 lands. Tests: - `a_backend_response_content_is_forbidden_for_204_and_304_and_discarded_for_head` (`h2.rs`) pins the classifier. - `a_204_response_carrying_data_resets_its_backend_stream_and_a_head_response_discards_it` (`h2.rs`) drives `handle_data_frame` through three cases: - the reset: RST_STREAM(PROTOCOL_ERROR) alone, no GOAWAY, payload not queued; - the HEAD discard: no frame, payload not queued, no byte left in the buffer; - a GET 200 that forwards its payload. - e2e in `e2e/src/tests/h2_security_header_injection.rs`: - `test_h2_bodiless_response_data_never_reaches_h1_client`: 204, 304 and HEAD, with HEADERS and DATA in one write or 200 ms apart. - `test_h2_head_response_with_large_data_completes`: HEAD with 20, 60 and 200 KB of DATA, to an H1 client with a keep-alive follow-up and to an H2 client. - `test_h2_head_response_with_large_data_keeps_the_backend_connection`: HEAD with 20 KB on stream 1 and a GET on stream 3 over one backend connection. - The raw H2 mock now honours sozu's flow-control windows. Documented in `lib/src/protocol/mux/LIFECYCLE.md` §8.4, `doc/configure.md` and `CHANGELOG.md`. Fixes #1772 Signed-off-by: Florentin Dubois <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an H2 backend sent a header section without END_STREAM and without
content-length,pkawa::handle_headeraddedTransfer-Encoding: chunkedand framed the response chunked for an H1 client, including for a 1xx, a 204, a 304 and a response to HEAD. These have no content by definition (RFC 9110 §6.4.1), and RFC 9112 §6.1 forbids the field in a 1xx or 204. A 1xx never completed either, so an H1 client read a chunked 103 and never the final response.Such a response now gains no framing:
main, the H2 client stream was retired without END_STREAM, and the backend stream was reset while its trailer HEADERS was in flight. The closed-stream check then answered with GOAWAY(STREAM_CLOSED) for the whole backend connection. Keeping the stream open until END_STREAM needs no reset and no memory of reset streams. One trade-off: a backend that never ends such a stream is bounded by the stream timeout, as for any other response.content-lengthis removed from a 1xx or a 204, where a server MUST NOT send it, and kept on a 304 or a response to HEAD (RFC 9110 §8.6).:status 101, which HTTP/2 does not support (RFC 9113 §8.6), is now a stream error (PROTOCOL_ERROR) answered 502. It used to reach the H1 upgrade path, which closed the session.DATA carrying a payload on a 204, a 304 or a response to HEAD is still forwarded. That is #1772, handled by #1775.
Tests:
a_bodiless_h2_response_gains_no_transfer_encoding_towards_an_h1_client(h1.rs): head bytes and completion for 103, 204, 304 and HEAD, with and withoutcontent-length, plus a GET 200 control.a_101_response_is_a_stream_protocol_error(pkawa.rs).e2e/src/tests/h2_security_header_injection.rs:test_h2_bodiless_response_head_has_no_transfer_encodingtest_h2_bodiless_response_ends_the_h2_client_stream: 204, 304 and HEAD, each ended by trailers or by an empty DATA frame.test_h2_bodiless_response_end_keeps_the_backend_connection: a second stream on the same backend connection, no GOAWAY or RST_STREAM towards the backend.test_h2_backend_interim_response_reaches_the_client: 103 then 200, to an H1 and an H2 client.test_h2_backend_101_is_a_bad_gatewayDocumented in
lib/src/protocol/mux/LIFECYCLE.md§8.4 andCHANGELOG.md.Fixes #1776