From d439e7dd53dae574443ed65a61fff9cdf7257848 Mon Sep 17 00:00:00 2001 From: Sumant Awasthi Date: Wed, 12 Jan 2022 11:39:02 +0530 Subject: [PATCH] made httpVersion first param in ClientParams, made relevant changes --- zio-http/src/main/scala/zhttp/service/Client.scala | 10 +++++----- .../test/scala/zhttp/http/GetBodyAsStringSpec.scala | 6 +++--- zio-http/src/test/scala/zhttp/internal/HttpGen.scala | 4 ++-- .../test/scala/zhttp/internal/HttpRunnableSpec.scala | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/zio-http/src/main/scala/zhttp/service/Client.scala b/zio-http/src/main/scala/zhttp/service/Client.scala index 5a5261813a..ac76ff3362 100644 --- a/zio-http/src/main/scala/zhttp/service/Client.scala +++ b/zio-http/src/main/scala/zhttp/service/Client.scala @@ -111,14 +111,14 @@ object Client { method: Method, url: URL, ): ZIO[EventLoopGroup with ChannelFactory, Throwable, ClientResponse] = - request(ClientParams(method, url)) + request(ClientParams(method = method, url = url)) def request( method: Method, url: URL, sslOptions: ClientSSLOptions, ): ZIO[EventLoopGroup with ChannelFactory, Throwable, ClientResponse] = - request(ClientParams(method, url), sslOptions) + request(ClientParams(method = method, url = url), sslOptions) def request( method: Method, @@ -126,7 +126,7 @@ object Client { headers: Headers, sslOptions: ClientSSLOptions, ): ZIO[EventLoopGroup with ChannelFactory, Throwable, ClientResponse] = - request(ClientParams(method, url, headers), sslOptions) + request(ClientParams(method = method, url = url, getHeaders = headers), sslOptions) def request( method: Method, @@ -134,7 +134,7 @@ object Client { headers: Headers, content: HttpData, ): ZIO[EventLoopGroup with ChannelFactory, Throwable, ClientResponse] = - request(ClientParams(method, url, headers, content)) + request(ClientParams(method = method, url = url, getHeaders = headers, data = content)) def request( req: ClientParams, @@ -148,12 +148,12 @@ object Client { make.flatMap(_.request(req, sslOptions)) final case class ClientParams( + httpVersion: HttpVersion = HttpVersion.HTTP_1_1, method: Method, url: URL, getHeaders: Headers = Headers.empty, data: HttpData = HttpData.empty, private val channelContext: ChannelHandlerContext = null, - httpVersion: HttpVersion = HttpVersion.HTTP_1_1, ) extends HeaderExtension[ClientParams] { self => def getBodyAsString: Option[String] = data match { diff --git a/zio-http/src/test/scala/zhttp/http/GetBodyAsStringSpec.scala b/zio-http/src/test/scala/zhttp/http/GetBodyAsStringSpec.scala index 71dfd8d831..eb2f348b8e 100644 --- a/zio-http/src/test/scala/zhttp/http/GetBodyAsStringSpec.scala +++ b/zio-http/src/test/scala/zhttp/http/GetBodyAsStringSpec.scala @@ -19,8 +19,8 @@ object GetBodyAsStringSpec extends DefaultRunnableSpec { check(charsetGen) { charset => val encoded = Client .ClientParams( - Method.GET, - URL(Path("/")), + method = Method.GET, + url = URL(Path("/")), getHeaders = Headers(HttpHeaderNames.CONTENT_TYPE.toString, s"text/html; charset=$charset"), data = HttpData.BinaryChunk(Chunk.fromArray("abc".getBytes())), ) @@ -33,7 +33,7 @@ object GetBodyAsStringSpec extends DefaultRunnableSpec { test("should map bytes to default utf-8 if no charset given") { val data = Chunk.fromArray("abc".getBytes()) val content = HttpData.BinaryChunk(data) - val request = Client.ClientParams(Method.GET, URL(Path("/")), data = content) + val request = Client.ClientParams(method = Method.GET, url = URL(Path("/")), data = content) val encoded = request.getBodyAsString val actual = Option(new String(data.toArray, HTTP_CHARSET)) assert(actual)(equalTo(encoded)) diff --git a/zio-http/src/test/scala/zhttp/internal/HttpGen.scala b/zio-http/src/test/scala/zhttp/internal/HttpGen.scala index 3878e24d86..4f19b42aa4 100644 --- a/zio-http/src/test/scala/zhttp/internal/HttpGen.scala +++ b/zio-http/src/test/scala/zhttp/internal/HttpGen.scala @@ -17,7 +17,7 @@ object HttpGen { url <- HttpGen.url headers <- Gen.listOf(HttpGen.header).map(Headers(_)) data <- dataGen - } yield ClientParams(method, url, headers, data) + } yield ClientParams(method = method, url = url, getHeaders = headers, data = data) def clientParamsForFileHttpData() = { for { @@ -25,7 +25,7 @@ object HttpGen { method <- HttpGen.method url <- HttpGen.url headers <- Gen.listOf(HttpGen.header).map(Headers(_)) - } yield ClientParams(method, url, headers, HttpData.fromFile(file)) + } yield ClientParams(method = method, url = url, getHeaders = headers, data = HttpData.fromFile(file)) } def cookies: Gen[Random with Sized, Cookie] = for { diff --git a/zio-http/src/test/scala/zhttp/internal/HttpRunnableSpec.scala b/zio-http/src/test/scala/zhttp/internal/HttpRunnableSpec.scala index 0e5ee4990b..aa0befe717 100644 --- a/zio-http/src/test/scala/zhttp/internal/HttpRunnableSpec.scala +++ b/zio-http/src/test/scala/zhttp/internal/HttpRunnableSpec.scala @@ -41,11 +41,11 @@ abstract class HttpRunnableSpec extends DefaultRunnableSpec { self => data = HttpData.fromString(content) response <- Client.request( Client.ClientParams( - method = method, - url = URL(path, Location.Absolute(Scheme.HTTP, "localhost", port)), - getHeaders = headers, - data = data, - httpVersion = httpVersion, + httpVersion, + method, + URL(path, Location.Absolute(Scheme.HTTP, "localhost", port)), + headers, + data, ), ClientSSLOptions.DefaultSSL, )