From eb8d83424670f2e528ff76141afc2686b8a739f7 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Thu, 4 Jun 2015 18:09:16 +0200 Subject: [PATCH] =htp #17051 fix BodyPartParser failing to detect initial boundary if it is chunked --- .../http/impl/engine/parsing/BodyPartParser.scala | 2 +- .../unmarshalling/MultipartUnmarshallersSpec.scala | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/BodyPartParser.scala b/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/BodyPartParser.scala index bf8578e53e..7086f937a9 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/BodyPartParser.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/engine/parsing/BodyPartParser.scala @@ -98,7 +98,7 @@ private[http] final class BodyPartParser(defaultContentType: ContentType, else parsePreamble(input, 0) } else parsePreamble(input, 0) } catch { - case NotEnoughDataException ⇒ continue((input, _) ⇒ tryParseInitialBoundary(input)) + case NotEnoughDataException ⇒ continue(input, 0)((newInput, _) ⇒ tryParseInitialBoundary(newInput)) } def parsePreamble(input: ByteString, offset: Int): StateResult = diff --git a/akka-http-tests/src/test/scala/akka/http/scaladsl/unmarshalling/MultipartUnmarshallersSpec.scala b/akka-http-tests/src/test/scala/akka/http/scaladsl/unmarshalling/MultipartUnmarshallersSpec.scala index 306571d2f7..505821ecfb 100644 --- a/akka-http-tests/src/test/scala/akka/http/scaladsl/unmarshalling/MultipartUnmarshallersSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/scaladsl/unmarshalling/MultipartUnmarshallersSpec.scala @@ -49,7 +49,7 @@ class MultipartUnmarshallersSpec extends FreeSpec with Matchers with BeforeAndAf |--XYZABC--""".stripMarginWithNewline("\r\n"))).to[Multipart.General] should haveParts( Multipart.General.BodyPart.Strict(HttpEntity.empty(MediaTypes.`text/xml`), List(Age(12)))) } - "an implicitly typed part (without headers)" in { + "an implicitly typed part (without headers) (Strict)" in { Unmarshal(HttpEntity(`multipart/mixed` withBoundary "XYZABC", """--XYZABC | @@ -57,6 +57,16 @@ class MultipartUnmarshallersSpec extends FreeSpec with Matchers with BeforeAndAf |--XYZABC--""".stripMarginWithNewline("\r\n"))).to[Multipart.General] should haveParts( Multipart.General.BodyPart.Strict(HttpEntity(ContentTypes.`text/plain(UTF-8)`, "Perfectly fine part content."))) } + "an implicitly typed part (without headers) (Default)" in { + val content = """--XYZABC + | + |Perfectly fine part content. + |--XYZABC--""".stripMarginWithNewline("\r\n") + val byteStrings = content.map(c ⇒ ByteString(c.toString)) // one-char ByteStrings + Unmarshal(HttpEntity.Default(`multipart/mixed` withBoundary "XYZABC", content.length, Source(byteStrings))) + .to[Multipart.General] should haveParts( + Multipart.General.BodyPart.Strict(HttpEntity(ContentTypes.`text/plain(UTF-8)`, "Perfectly fine part content."))) + } "one non-empty form-data part" in { Unmarshal(HttpEntity(`multipart/form-data` withBoundary "-", """---