From e066dd36fc13f7cc1c15618b1eaf4d7e3b217d6c Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Tue, 22 Jul 2014 17:47:32 +0200 Subject: [PATCH] =htc #15686 fix off-by-one error when creating strict entities for small payloads --- .../akka/http/parsing/HttpRequestParser.scala | 2 +- .../http/server/HttpServerPipelineSpec.scala | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/akka-http-core/src/main/scala/akka/http/parsing/HttpRequestParser.scala b/akka-http-core/src/main/scala/akka/http/parsing/HttpRequestParser.scala index 822fa1f3d2..1bd780011e 100644 --- a/akka-http-core/src/main/scala/akka/http/parsing/HttpRequestParser.scala +++ b/akka-http-core/src/main/scala/akka/http/parsing/HttpRequestParser.scala @@ -125,7 +125,7 @@ private[http] class HttpRequestParser(_settings: ParserSettings, else if (contentLength == 0) { emitRequestStart(emptyEntity(cth)) startNewMessage(input, bodyStart) - } else if (contentLength < input.size - bodyStart) { + } else if (contentLength <= input.size - bodyStart) { val cl = contentLength.toInt emitRequestStart(strictEntity(cth, input, bodyStart, cl)) startNewMessage(input, bodyStart + cl) diff --git a/akka-http-core/src/test/scala/akka/http/server/HttpServerPipelineSpec.scala b/akka-http-core/src/test/scala/akka/http/server/HttpServerPipelineSpec.scala index 3440e61c87..23b8c6ca0d 100644 --- a/akka-http-core/src/test/scala/akka/http/server/HttpServerPipelineSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/server/HttpServerPipelineSpec.scala @@ -89,7 +89,7 @@ class HttpServerPipelineSpec extends AkkaSpec with Matchers with BeforeAndAfterA } }) - "deliver the request entity as it comes in strictly for an immediately completed Strict entity" in pendingUntilFixed(new TestSetup { // broken because of #15686 + "deliver the request entity as it comes in strictly for an immediately completed Strict entity" in new TestSetup { send("""POST /strict HTTP/1.1 |Host: example.com |Content-Length: 12 @@ -102,7 +102,7 @@ class HttpServerPipelineSpec extends AkkaSpec with Matchers with BeforeAndAfterA uri = "http://example.com/strict", headers = List(Host("example.com")), entity = HttpEntity.Strict(ContentTypes.`application/octet-stream`, ByteString("abcdefghijkl"))) - }) + } "deliver the request entity as it comes in for a Default entity" in new TestSetup { send("""POST / HTTP/1.1 |Host: example.com @@ -146,7 +146,7 @@ class HttpServerPipelineSpec extends AkkaSpec with Matchers with BeforeAndAfterA } } - "deliver the second message properly after a Strict entity" in pendingUntilFixed(new TestSetup { // broken because of #15686 + "deliver the second message properly after a Strict entity" in new TestSetup { send("""POST /strict HTTP/1.1 |Host: example.com |Content-Length: 12 @@ -172,8 +172,8 @@ class HttpServerPipelineSpec extends AkkaSpec with Matchers with BeforeAndAfterA uri = "http://example.com/next-strict", headers = List(Host("example.com")), entity = HttpEntity.Strict(ContentTypes.`application/octet-stream`, ByteString("mnopqrstuvwx"))) - }) - "deliver the second message properly after a Default entity" in pendingUntilFixed(new TestSetup { // broken because of #15686 + } + "deliver the second message properly after a Default entity" in new TestSetup { send("""POST / HTTP/1.1 |Host: example.com |Content-Length: 12 @@ -206,8 +206,8 @@ class HttpServerPipelineSpec extends AkkaSpec with Matchers with BeforeAndAfterA case HttpRequest(HttpMethods.POST, _, _, HttpEntity.Strict(_, data), _) ⇒ data shouldEqual (ByteString("abcde")) } - }) - "deliver the second message properly after a Chunked entity" in pendingUntilFixed(new TestSetup { // broken because of #15686 + } + "deliver the second message properly after a Chunked entity" in new TestSetup { send("""POST /chunked HTTP/1.1 |Host: example.com |Transfer-Encoding: chunked @@ -243,7 +243,7 @@ class HttpServerPipelineSpec extends AkkaSpec with Matchers with BeforeAndAfterA case HttpRequest(HttpMethods.POST, _, _, HttpEntity.Strict(_, data), _) ⇒ data shouldEqual (ByteString("abcde")) } - }) + } "close the request entity stream when the entity is complete for a Default entity" in new TestSetup { send("""POST / HTTP/1.1