From cf27712266adf4db5311b98d9b03a352bf085cca Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Mon, 3 Nov 2014 15:58:53 +0100 Subject: [PATCH] =htc #16175 regard `raw-request-uri-header` setting --- .../http/engine/parsing/HttpRequestParser.scala | 8 ++++++-- .../http/engine/parsing/RequestParserSpec.scala | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpRequestParser.scala b/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpRequestParser.scala index 582bc49dd3..9c25a3e950 100644 --- a/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpRequestParser.scala +++ b/akka-http-core/src/main/scala/akka/http/engine/parsing/HttpRequestParser.scala @@ -110,8 +110,12 @@ private[http] class HttpRequestParser(_settings: ParserSettings, hostHeaderPresent: Boolean, closeAfterResponseCompletion: Boolean): StateResult = if (hostHeaderPresent || protocol == HttpProtocols.`HTTP/1.0`) { def emitRequestStart(createEntity: Source[ParserOutput.RequestOutput] ⇒ RequestEntity, - headers: List[HttpHeader] = headers) = - emit(ParserOutput.RequestStart(method, uri, protocol, headers, createEntity, closeAfterResponseCompletion)) + headers: List[HttpHeader] = headers) = { + val allHeaders = + if (rawRequestUriHeader) `Raw-Request-URI`(new String(uriBytes, HttpCharsets.`US-ASCII`.nioCharset)) :: headers + else headers + emit(ParserOutput.RequestStart(method, uri, protocol, allHeaders, createEntity, closeAfterResponseCompletion)) + } teh match { case None ⇒ diff --git a/akka-http-core/src/test/scala/akka/http/engine/parsing/RequestParserSpec.scala b/akka-http-core/src/test/scala/akka/http/engine/parsing/RequestParserSpec.scala index e010153160..08c7e79d94 100644 --- a/akka-http-core/src/test/scala/akka/http/engine/parsing/RequestParserSpec.scala +++ b/akka-http-core/src/test/scala/akka/http/engine/parsing/RequestParserSpec.scala @@ -228,6 +228,23 @@ class RequestParserSpec extends FreeSpec with Matchers with BeforeAndAfterAll { closeAfterResponseCompletion shouldEqual Seq(false) } + "support `rawRequestUriHeader` setting" in new Test { + override protected def newParser: HttpRequestParser = new HttpRequestParser(parserSettings, rawRequestUriHeader = true)() + + """GET /f%6f%6fbar?q=b%61z HTTP/1.1 + |Host: ping + |Content-Type: application/pdf + | + |""" should parseTo( + HttpRequest( + GET, + "/foobar?q=baz", + List( + `Raw-Request-URI`("/f%6f%6fbar?q=b%61z"), + Host("ping")), + HttpEntity.empty(`application/pdf`))) + } + "reject a message chunk with" - { val start = """PATCH /data HTTP/1.1