Skip to content

fix: preserve received HTTP/1 trailer field order - #1620

Open
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/http1-trailer-field-order
Open

He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/http1-trailer-field-order

Conversation

@He-Pin

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

Copy link
Copy Markdown
Member

Motivation

The HTTP/1 parser collects trailer fields by prepending each field. It used that list directly in the terminal chunk, reversing the received order of repeated list-valued fields.

Modification

Restore received order when constructing the terminal chunk. Assert the ordered trailer list directly on the LastChunk produced by the HTTP/1.1 response parser, without converting the entity to strict.

Result

The trailer sequence follows the received order. Rendering, the empty terminal chunk, and public signatures are unchanged.

Tests

JDK 17: the focused native ResponseParserSpec case passed on Scala 2.13.18 and 3.3.9 (1/1 each). The Scala 2 baseline failed on reversed trailer order as expected. Scoped formatting and license-header checks passed; no full CI run.

References

None - RFC 9110 §5.3 and §6.5.2.

@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.

Fix is correct. Nits:

  • Why this went unnoticed: the RequestParserSpec/ResponseParserSpec trailer cases expect LastChunk(..., List(Foo, Bar)), but StrictEqualHttpRequest/StrictEqualHttpResponse compare via toStrict, which drops trailers. A parser-level assertion (or fixing that comparison) would be more targeted than the end-to-end test.
  • The test comment says repeated lines "are combined", but they aren't.
  • The test is in the concrete ClientServerSpec body while sibling PRs use ClientServerSpecBase.

@He-Pin
He-Pin force-pushed the fix/http1-trailer-field-order branch from bf55d90 to fa20ae2 Compare November 26, 2026 11:58
@He-Pin
He-Pin requested a review from pjfanning November 26, 2026 11:59

@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 parser-level assertion is the right test. One thing left: it is wrapped in if (mode == "CRLF") and builds its input with crlf(...), so it does not run in ResponseParserLFSpec. The fix does not depend on the line ending, so could the test use prep/newLine like its neighbours and run in both modes? (Same point as on #1644.)

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