From 3fd9fb96be88511614e4f081c1e0212fc64a7e41 Mon Sep 17 00:00:00 2001 From: "He-Pin(kerr)" Date: Fri, 27 Nov 2026 02:51:59 +0800 Subject: [PATCH] test: preserve HTTP/1.1 response trailers across input segments Motivation: A valid chunked response must preserve declared trailers when the final line arrives separately. Modification: Run the existing focused test in both header-line modes. Use the suite separator for the response head and keep standard CRLF for the chunked framing. Result: Both parser suites verify the final trailer and message completion. No runtime change. Tests: ResponseParserCRLFSpec and ResponseParserLFSpec, one focused case each on Scala 2.13.18 and 3.3.9 with JDK 17; scoped Scalafmt and git diff --check. References: Apache Pekko HTTP #1644; RFC 9112 sections 2.2 and 7.1. --- .../engine/parsing/ResponseParserSpec.scala | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/parsing/ResponseParserSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/parsing/ResponseParserSpec.scala index a3201e95c..d8f6f9631 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/parsing/ResponseParserSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/parsing/ResponseParserSpec.scala @@ -343,6 +343,37 @@ abstract class ResponseParserSpec(mode: String, newLine: String) extends PekkoSp closeAfterResponseCompletion shouldEqual Seq(false) } + "retain a declared response trailer when the terminating empty line arrives separately" in new Test { + val field = RawHeader("X-Trace", "complete") + val declaration = headers.Trailer(Seq(field.name)) + val terminalChunk = LastChunk(trailer = List(field)) + val responseStart = prep(s"""HTTP/1.1 200 OK + |Transfer-Encoding: chunked + |Content-Type: application/pdf + |Trailer: ${field.name} + | + |""") + // The header section follows the suite mode; chunk framing uses CRLF in both modes. + val beforeEmptyLine = responseStart + crlf(s"""0 + |${field.name}: ${field.value} + |""") + + val parsed = collectBlocking( + Source(List(beforeEmptyLine, crlf("\n"))) + .map(input => SessionBytes(TLSPlacebo.dummySession, ByteString(input))) + .via(newParserStage()) + .filterNot(_ == NeedNextRequestMethod)) + + parsed match { + case Seq(ResponseStart(status, protocol, _, headers, _, _), EntityChunk(chunk), MessageEnd) => + status shouldBe OK + protocol shouldBe `HTTP/1.1` + headers should contain(declaration) + chunk shouldBe terminalChunk + case other => fail(s"Expected a response start, one terminal chunk and a message end, got ${other}") + } + } + "message end" in new Test { Seq( prep(start),