diff --git a/akka-http-core/src/main/scala/akka/http/engine/parsing/BodyPartParser.scala b/akka-http-core/src/main/scala/akka/http/engine/parsing/BodyPartParser.scala index 949548cd71..983bd6911a 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/parsing/BodyPartParser.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/parsing/BodyPartParser.scala @@ -56,7 +56,6 @@ private[http] final class BodyPartParser(defaultContentType: ContentType, private[this] var output = collection.immutable.Queue.empty[Output] // FIXME this probably is too wasteful private[this] var state: ByteString ⇒ StateResult = tryParseInitialBoundary - private[this] var receivedInitialBoundary = false private[this] var terminated = false def warnOnIllegalHeader(errorInfo: ErrorInfo): Unit = @@ -79,10 +78,8 @@ private[http] final class BodyPartParser(defaultContentType: ContentType, if (output.nonEmpty) ctx.push(dequeue()) else if (ctx.isFinishing) { - if (terminated || !receivedInitialBoundary) - ctx.finish() - else - ctx.pushAndFinish(ParseError(ErrorInfo("Unexpected end of multipart entity"))) + if (terminated) ctx.finish() + else ctx.pushAndFinish(ParseError(ErrorInfo("Unexpected end of multipart entity"))) } else ctx.pull() } @@ -95,10 +92,8 @@ private[http] final class BodyPartParser(defaultContentType: ContentType, try { if (boundary(input, 0)) { val ix = boundaryLength - if (crlf(input, ix)) { - receivedInitialBoundary = true - parseHeaderLines(input, ix + 2) - } else if (doubleDash(input, ix)) terminate() + if (crlf(input, ix)) parseHeaderLines(input, ix + 2) + else if (doubleDash(input, ix)) terminate() else parsePreamble(input, 0) } else parsePreamble(input, 0) } catch { diff --git a/akka-http-tests/src/test/scala/akka/http/unmarshalling/UnmarshallingSpec.scala b/akka-http-tests/src/test/scala/akka/http/unmarshalling/UnmarshallingSpec.scala index 337763f283..976a1c7209 100644 --- a/akka-http-tests/src/test/scala/akka/http/unmarshalling/UnmarshallingSpec.scala +++ b/akka-http-tests/src/test/scala/akka/http/unmarshalling/UnmarshallingSpec.scala @@ -37,14 +37,6 @@ class UnmarshallingSpec extends FreeSpec with Matchers with BeforeAndAfterAll wi "The MultipartUnmarshallers." - { "multipartGeneralUnmarshaller should correctly unmarshal 'multipart/*' content with" - { - "an empty entity" in { - Unmarshal(HttpEntity(`multipart/mixed` withBoundary "XYZABC", ByteString.empty)).to[Multipart.General] should haveParts() - } - "an entity without initial boundary" in { - Unmarshal(HttpEntity(`multipart/mixed` withBoundary "XYZABC", - """this is - |just preamble text""".stripMarginWithNewline("\r\n"))).to[Multipart.General] should haveParts() - } "an empty part" in { Unmarshal(HttpEntity(`multipart/mixed` withBoundary "XYZABC", """--XYZABC @@ -111,6 +103,16 @@ class UnmarshallingSpec extends FreeSpec with Matchers with BeforeAndAfterAll wi } "multipartGeneralUnmarshaller should reject illegal multipart content with" - { + "an empty entity" in { + Await.result(Unmarshal(HttpEntity(`multipart/mixed` withBoundary "XYZABC", ByteString.empty)) + .to[Multipart.General].failed, 1.second).getMessage shouldEqual "Unexpected end of multipart entity" + } + "an entity without initial boundary" in { + Await.result(Unmarshal(HttpEntity(`multipart/mixed` withBoundary "XYZABC", + """this is + |just preamble text""".stripMarginWithNewline("\r\n"))) + .to[Multipart.General].failed, 1.second).getMessage shouldEqual "Unexpected end of multipart entity" + } "a stray boundary" in { Await.result(Unmarshal(HttpEntity(`multipart/form-data` withBoundary "ABC", """--ABC