Skip to content

Normalize outgoing HTTP/2 initial fields - #1463

Merged
He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/http2-initial-field-normalization
Nov 17, 2026
Merged

He-Pin merged 1 commit into
apache:mainfrom
He-Pin:fix/http2-initial-field-normalization

Conversation

@He-Pin

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

Copy link
Copy Markdown
Member

Motivation

Shared HTTP models can contain fields intended for HTTP/1. HTTP/2 outbound field sections need a consistent policy for connection-specific fields across initial headers and trailers.

Modification

  • Apply one shared case-insensitive outbound field policy to initial fields and streamed or attribute-supplied trailers, covering modeled, raw and custom headers.
  • Suppress Connection, Keep-Alive, Proxy-Connection, Transfer-Encoding and Upgrade.
  • Retain TE only for initial requests when its whole value is trailers, ignoring surrounding whitespace and case, and emit te: trailers. Drop TE from responses and trailers.
  • Preserve direction flags, Host handling and HTTP/1 behavior. Arbitrary fields nominated by Connection in intermediary forwarding remain outside this change.
  • Add focused output-model coverage for the shared policy.

Result

Initial and trailer HTTP/2 field sections use the same suppression policy without rejecting models shared with HTTP/1. This does not change intermediary forwarding or claim full intermediary compliance.

Tests

34 focused renderer model tests compiled and passed against cached HTTP module classes with Scala 2.13.18 and fatal warnings enabled. Formatter and diff checks passed. Full CI for this exact revision is queued.

The preceding revision recorded 28 HttpMessageRenderingSpec tests, four ordinary HTTP/2 round trips, cross-Scala header checks, documentation generation and targeted MiMa checks. Those historical results are not new full-suite, Scala 3 or MiMa validation of this revision.

References

  • RFC 9113 section 8.2.2.
  • Independently implemented outbound-field normalization, prompted by comparing Netty's HTTP/2 conversion behavior; no upstream code copied.

@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. Dropping Upgrade, Keep-Alive, Proxy-Connection and non-trailers TE from HTTP/2 output is right per RFC 9113 §8.2.2, and keeping the HTTP/1 models usable is the right call. Two points about where the rule lives:

  1. Two suppression lists. renderHeaders already suppresses Connection and Transfer-Encoding (modeled and raw) with its own warnings. normalizeInitialHeaders now filters those, plus the new ones, before renderHeaders runs. So for initial fields the old branches never fire, but they still apply to trailers, and the two lists can drift apart. Could the new rules go into the existing renderHeaders match instead (including the CustomHeader case, which currently skips suppression), so there's one list?
  2. Trailers. The comment explains that the pre-filter is limited to initial fields because renderHeaders also renders streamed trailers. But §8.2.2 forbids connection-specific fields in any field section, trailers included, so applying the same rule there would be correct rather than a side effect. TE is the one special case: it's only meaningful (as trailers) in request headers, so it should be dropped from trailers entirely.
  3. Docs. The "Initial request fields" / "Initial response fields" sections describe protocol-mandated behaviour. A single line saying that connection-specific headers set on the model are dropped (with a warning) when sent over HTTP/2 would be enough.

Motivation:
Connection-specific fields must not be emitted in HTTP/2 field sections.
Use one policy for initial headers and trailers, including custom headers.

Modification:
Consolidate connection-field suppression before the custom-header branch.
Use a boolean filter without per-header Option allocation or repeated values.
Retain canonical TE trailers only in initial request headers.
Apply the same policy to streamed and attribute-supplied trailers.
Replace detailed protocol documentation with a short user-facing statement.

Result:
HTTP/1 models stay usable while HTTP/2 output consistently omits unsupported
connection fields. Existing renderHeaders signatures remain unchanged.

Tests:
- Changed renderer and spec compile with cached Scala 2.13.18 and fatal warnings.
- All 34 HttpMessageRenderingSpec model-level tests pass, including initial
  request/response, custom header, streamed trailer and attribute trailer cases.
- Compilation and tests use previously cached HTTP core module classes and
  dependencies, not a clean exact-main build. No wire or parser scenarios ran.
- Cached Scalafmt 3.11.5 reports both Scala files unchanged.
- git diff --check passes. Full build, cross-Scala, MiMa and docs build not run.

References:
Refs apache#1463; RFC 9113 section 8.2.2; pjfanning review.
@He-Pin
He-Pin force-pushed the fix/http2-initial-field-normalization branch from 7ae2142 to cae8ca4 Compare November 17, 2026 17:44
@He-Pin
He-Pin requested a review from pjfanning November 17, 2026 17:47

@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. Minor, not blocking: renderHeaders infers isTrailer = !shouldRenderAutoHeaders. That's correct today, since the streamed-trailer call in Http2StreamHandling is the only caller passing false, but an explicit isTrailer parameter would stop a future non-trailer caller from silently losing te: trailers.

@He-Pin
He-Pin merged commit c6184f0 into apache:main Nov 17, 2026
6 checks passed
@He-Pin
He-Pin deleted the fix/http2-initial-field-normalization branch November 17, 2026 20:06
pjfanning added a commit that referenced this pull request Nov 19, 2026
Motivation:
HTTP/2 field restrictions apply to initial headers and trailers.
Connection-specific fields set as raw or custom headers, or in trailers,
were not consistently suppressed.

Modification:
Share case-insensitive suppression of Connection, Keep-Alive,
Proxy-Connection, Transfer-Encoding and Upgrade across modeled, raw and
custom fields, retaining TE: trailers only in initial requests.

Result:
Outbound field sections follow a consistent policy without changing
HTTP/1 behavior.

Tests:
- http2-tests/testOnly HttpMessageRenderingSpec (backport of #1463)

References:
Backport of #1463 (c6184f0)

Co-authored-by: He-Pin(kerr) <[email protected]>
pjfanning added a commit that referenced this pull request Nov 19, 2026
Motivation:
Several recently merged PRs left review points unaddressed: docs that
were asked to be dropped, comments and tests that were suggested, and
small API and internal tidy-ups.

Modification:
- Add a Scala FilenameEncoding alias and values to Multipart.FormData
  and use them in the Scala toEntity signature and tests (#1494).
- Render the form-data Content-Disposition header directly instead of
  rendering it twice and slicing off the prefix (#1494).
- Drop the docs paragraph about unpaired URI surrogates (#1426) and the
  cookie -0000 sentence in request-level.md (#1493).
- Fix the javadsl Multipart.FormData doc the same way #1483 fixed the
  scaladsl one.
- Comment the cookie date rule copies so they stay in sync (#1458).
- Test custom methods starting with Q next to the QUERY fast path
  (#1477).
- Use one root package import and a dilated timeout in
  HeaderCompressionSpec (#1438).
- Pass isTrailer to HttpMessageRendering.renderHeaders explicitly
  (#1463).
- Remove the unused forwarding overloads in Handshake.Client and
  EnabledPingState (#1436, #1462).
- Move the media type model checks from the routing spec to a new
  http-core MediaTypesSpec (#1437, #1454).
- Hash the WebSocket key without String.valueOf (#1439).

Result:
The review points are addressed. The only public API change is the
added Scala FilenameEncoding alias.

Tests:
- http-core/testOnly MultipartSpec MultipartsSpec MediaTypesSpec
  RequestParserCRLFSpec RequestParserLFSpec HeaderCompressionSpec
  WebSocketClientSpec HeaderSpec HttpHeaderSpec: 314 passed
- http2-tests/testOnly HttpMessageRenderingSpec Http2PingSchedulingSpec:
  38 passed
- http-tests/testOnly FileAndResourceDirectivesSpec: 63 passed
- http-core/mimaReportBinaryIssues: passed

References:
Refs #1426, #1436, #1437, #1438, #1439, #1454, #1458, #1462, #1463,
#1477, #1483, #1493, #1494
He-Pin added a commit that referenced this pull request Nov 28, 2026
Motivation:
The positive HTTP/2 request test checks that TE: trailers is accepted,
but not that the parsed field is available through typed header lookup.

Modification:
Give the existing GET fixture an authority and assert that its typed TE
header contains exactly the trailers marker.

Result:
The test now catches a dropped or unmodeled field without introducing
another fixture or changing production code.

Tests:
- Focused RequestParsingSpec case passed on JDK 17 with Scala 2.13.18
  and 3.3.9, on unmodified main and published Pekko HTTP 2.0.0.
- Scoped scalafmt and git diff --check passed.
- The full sbt test suite was not run.

References:
Refs #1463; RFC 9113 sections 8.2.2 and 8.3.1.
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