From 1e8d81b211a1fe9ec4cd13e3e4e3745f570cd18d Mon Sep 17 00:00:00 2001 From: Shubham Girdhar <girdharshubham@hotmail.com> Date: Wed, 2 Feb 2022 18:12:14 +0530 Subject: [PATCH] refactor: remove host header changes and RequestSpec (#945) --- .../src/main/scala/zhttp/http/Request.scala | 14 ++---- .../test/scala/zhttp/http/RequestSpec.scala | 45 ------------------- 2 files changed, 4 insertions(+), 55 deletions(-) delete mode 100644 zio-http/src/test/scala/zhttp/http/RequestSpec.scala diff --git a/zio-http/src/main/scala/zhttp/http/Request.scala b/zio-http/src/main/scala/zhttp/http/Request.scala index 41d3b81e4b..a930ea5ed5 100644 --- a/zio-http/src/main/scala/zhttp/http/Request.scala +++ b/zio-http/src/main/scala/zhttp/http/Request.scala @@ -98,16 +98,10 @@ object Request { remoteAddress: Option[InetAddress] = None, data: HttpData = HttpData.Empty, ): Request = { - val hostHeaders = (url.host, url.port) match { - case (Some(name), None) => Headers.host(name) - case (Some(name), Some(80 | 443)) => Headers.host(name) - case (Some(name), Some(port)) => Headers.host(s"${name}:${port}") - case _ => Headers.empty - } - val m = method - val u = url - val h = headers ++ hostHeaders - val ra = remoteAddress + val m = method + val u = url + val h = headers + val ra = remoteAddress new Request { override def method: Method = m override def url: URL = u diff --git a/zio-http/src/test/scala/zhttp/http/RequestSpec.scala b/zio-http/src/test/scala/zhttp/http/RequestSpec.scala deleted file mode 100644 index 6c90a39710..0000000000 --- a/zio-http/src/test/scala/zhttp/http/RequestSpec.scala +++ /dev/null @@ -1,45 +0,0 @@ -package zhttp.http - -import zio.test.Assertion.{equalTo, isSome} -import zio.test.{DefaultRunnableSpec, _} - -object RequestSpec extends DefaultRunnableSpec { - def spec = suite("Request") { - suite("host header") { - suite("without port") { - test("non-ssl add hostname") { - val url = URL.fromString("http://example.com").getOrElse(null) - val req = Request(url = url) - assert(req.getHost)(isSome(equalTo("example.com"))) - } + - test("ssl add hostname") { - val url = URL.fromString("https://example.com").getOrElse(null) - val req = Request(url = url) - assert(req.getHost)(isSome(equalTo("example.com"))) - } - } + - suite("add port") { - test("non-ssl with non-default port") { - val url = URL.fromString("http://example.com:8090").getOrElse(null) - val req = Request(url = url) - assert(req.getHost)(isSome(equalTo("example.com:8090"))) - } + - test("non-ssl with default port") { - val url = URL.fromString("http://example.com:80").getOrElse(null) - val req = Request(url = url) - assert(req.getHost)(isSome(equalTo("example.com"))) - } + - test("ssl with non-default port") { - val url = URL.fromString("https://example.com:8090").getOrElse(null) - val req = Request(url = url) - assert(req.getHost)(isSome(equalTo("example.com:8090"))) - } + - test("ssl with default port") { - val url = URL.fromString("https://example.com:443").getOrElse(null) - val req = Request(url = url) - assert(req.getHost)(isSome(equalTo("example.com"))) - } - } - } - } -}