Skip to content

fix(mux-h2): drop trailer fields of a Content-Length-framed message - #1731

Merged
FlorentinDUBOIS merged 2 commits into
mainfrom
fix/h2-h1-length-framed-trailers
Oct 1, 2026
Merged

FlorentinDUBOIS merged 2 commits into
mainfrom
fix/h2-h1-length-framed-trailers

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1730

Change

H2→H1: drop the trailer fields of a Content-Length-framed message instead of writing them after the body.

HTTP/1.1 carries a trailer section only with chunked transfer coding (RFC 9112 §7.1.2), and a message framed by Content-Length ends with its last body byte (RFC 9112 §6.3). RFC 9110 §6.5 lets a recipient discard trailers.

  • ConnectionH1::drop_length_framed_trailers (lib/src/protocol/mux/h1.rs) runs in ConnectionH1::writable before kawa's H1 prepare. For a BodySize::Length message whose queue ends with a trailer block, it removes the trailer fields and clears end_header on the closing flags, so nothing is written after the body. This covers requests to an H1 backend and responses to an H1 client.
  • Each dropped block logs a warn! and increments h2.trailers_dropped_content_length at the write.
  • pkawa::handle_trailer still validates, elides and queues the block, so H2 peers keep these trailers and the h2.trailer.*_elided counters are unchanged.
  • Docs: doc/configure.md metric row, lib/src/protocol/mux/LIFECYCLE.md §8.4, CHANGELOG (Unreleased, Security).

#1724 (last chunk before H2 trailers on a chunked H1 body) is merged; this branch is rebased on it.

Tests

  • a_length_framed_message_writes_no_trailer_to_an_h1_peer (h1.rs): request and response, with one trailer field and with none; H1 bytes are exactly hello.
  • a_length_framed_header_section_is_not_taken_for_trailers (h1.rs).
  • a_length_framed_trailer_block_reaches_an_h2_peer (converter.rs): DATA, then HEADERS with END_STREAM holding the trailer field.
  • handle_trailer_filters_and_keeps_a_length_framed_block (pkawa.rs): elision counters fire for a length-framed block.
  • test_h2_length_framed_request_trailers_keep_h1_backend_framing (e2e): the backend bytes are split by HTTP/1.1 framing, and the byte after the body starts the next request line.

Validation

  • fmt, MSRV clippy, rustdoc -D warnings, cargo test -p sozu-lib --all-features, fuzz build, and the 4 check_doc_citations.py modes all exit 0.
  • e2e protocol_pair_matrix and h2_security_header_injection pass.
  • e2e trailer: 21 passed, 1 failed, test_h1_trailer_field_limit_exceeded_split_closes_backend. That failure is pre-existing on main (H1→H1, chunked body) and is being fixed separately.

HTTP/1.1 carries a trailer section only with chunked coding (RFC 9112
section 6.3, 7.1), but kawa's H1 serializer wrote the trailer fields and
a closing empty line of an H2 message framed by content-length after the
body, for a request to an H1 backend and for a response to an H1 client.

ConnectionH1::writable now drops such a trailer block before writing
(RFC 9110 section 6.5.1) and counts it in
h2.trailers_dropped_content_length. pkawa::handle_trailer keeps
validating, eliding and queuing the block, so an H2 peer still receives
these trailers. Correct the comments and the metric description that
said these trailers were already dropped.

Closes #1730

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS force-pushed the fix/h2-h1-length-framed-trailers branch from 342c269 to 64402cf Compare October 1, 2026 19:19
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 55206dc into main Oct 1, 2026
23 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.

H2→H1: trailer fields of a Content-Length-framed message are written after the body

1 participant