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),