From 09c656c21dd14c1d9fc2e212f50f268c6de13232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Andr=C3=A9n?= Date: Tue, 23 Aug 2016 01:58:10 +0200 Subject: [PATCH] =htc Bugfix #21243 absolute request target parsing broken (#21244) --- .../http/impl/util/ByteStringParserInput.scala | 2 +- .../impl/engine/parsing/RequestParserSpec.scala | 14 +++++++++++--- .../http/impl/model/parser/HttpHeaderSpec.scala | 2 ++ .../http/impl/util/ByteStringParserInputSpec.scala | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/akka-http-core/src/main/scala/akka/http/impl/util/ByteStringParserInput.scala b/akka-http-core/src/main/scala/akka/http/impl/util/ByteStringParserInput.scala index 0ef5d69346..bd7b88ddfe 100644 --- a/akka-http-core/src/main/scala/akka/http/impl/util/ByteStringParserInput.scala +++ b/akka-http-core/src/main/scala/akka/http/impl/util/ByteStringParserInput.scala @@ -23,7 +23,7 @@ import akka.util.ByteString final class ByteStringParserInput(bytes: ByteString) extends DefaultParserInput { override def charAt(ix: Int): Char = (bytes(ix) & 0xFF).toChar override def length: Int = bytes.size - override def sliceString(start: Int, end: Int): String = bytes.slice(start, end - start).decodeString(StandardCharsets.ISO_8859_1) + override def sliceString(start: Int, end: Int): String = bytes.slice(start, end).decodeString(StandardCharsets.ISO_8859_1) override def sliceCharArray(start: Int, end: Int): Array[Char] = StandardCharsets.ISO_8859_1.decode(bytes.slice(start, end).asByteBuffer).array() } diff --git a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala index ccf1b3cdc3..5dfe4a6ace 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/engine/parsing/RequestParserSpec.scala @@ -42,7 +42,7 @@ class RequestParserSpec extends FreeSpec with Matchers with BeforeAndAfterAll { akka.event-handlers = ["akka.testkit.TestEventListener"] akka.loglevel = WARNING akka.http.parsing.max-header-value-length = 32 - akka.http.parsing.max-uri-length = 20 + akka.http.parsing.max-uri-length = 40 akka.http.parsing.max-content-length = 4000000000""") implicit val system = ActorSystem(getClass.getSimpleName, testConf) import system.dispatcher @@ -79,6 +79,14 @@ class RequestParserSpec extends FreeSpec with Matchers with BeforeAndAfterAll { closeAfterResponseCompletion shouldEqual Seq(false) } + "with absolute uri in request-target" in new Test { + """GET http://127.0.0.1:8080/hello HTTP/1.1 + |Host: 127.0.0.1:8080 + | + |""" should parseTo(HttpRequest(uri = "http://127.0.0.1:8080/hello", headers = List(Host("127.0.0.1", 8080)))) + closeAfterResponseCompletion shouldEqual Seq(false) + } + "with 3 headers and a body" in new Test { """POST /resource/yes HTTP/1.0 |User-Agent: curl/7.19.7 xyz @@ -408,9 +416,9 @@ class RequestParserSpec extends FreeSpec with Matchers with BeforeAndAfterAll { } "a too-long URI" in new Test { - "GET /23456789012345678901 HTTP/1.1" should parseToError( + "GET /2345678901234567890123456789012345678901 HTTP/1.1" should parseToError( RequestUriTooLong, - ErrorInfo("URI length exceeds the configured limit of 20 characters")) + ErrorInfo("URI length exceeds the configured limit of 40 characters")) } "HTTP version 1.2" in new Test { diff --git a/akka-http-core/src/test/scala/akka/http/impl/model/parser/HttpHeaderSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/model/parser/HttpHeaderSpec.scala index e4e3b92998..0e16cfb210 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/model/parser/HttpHeaderSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/model/parser/HttpHeaderSpec.scala @@ -293,6 +293,8 @@ class HttpHeaderSpec extends FreeSpec with Matchers { "Host: [2001:db8::1]" =!= Host("[2001:db8::1]") "Host: [::FFFF:129.144.52.38]" =!= Host("[::FFFF:129.144.52.38]") "Host: spray.io:80000" =!= ErrorInfo("Illegal HTTP header 'Host': requirement failed", "Illegal port: 80000") + "Host: 127.0.0.1:9000" =!= Host("127.0.0.1", 9000) + "Host: 127.0.0.1" =!= Host("127.0.0.1") } "If-Match" in { diff --git a/akka-http-core/src/test/scala/akka/http/impl/util/ByteStringParserInputSpec.scala b/akka-http-core/src/test/scala/akka/http/impl/util/ByteStringParserInputSpec.scala index 67b0a3b574..cc3229e6f5 100644 --- a/akka-http-core/src/test/scala/akka/http/impl/util/ByteStringParserInputSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/impl/util/ByteStringParserInputSpec.scala @@ -18,6 +18,7 @@ class ByteStringParserInputSpec extends WordSpec with Matchers { "slice the bytes correctly into a string" in { parser.sliceString(0, 3) should ===("abc") + parser.sliceString(3, 5) should ===("de") } "slice the bytes correctly into a char array" in {