diff --git a/zio-http/src/main/scala/zhttp/service/Client.scala b/zio-http/src/main/scala/zhttp/service/Client.scala index 7a3b3e0bac..74d074172e 100644 --- a/zio-http/src/main/scala/zhttp/service/Client.scala +++ b/zio-http/src/main/scala/zhttp/service/Client.scala @@ -13,7 +13,7 @@ import zhttp.http.URL.Location import zhttp.http._ import zhttp.http.headers.HeaderExtension import zhttp.service -import zhttp.service.Client.{ClientParams, ClientResponse} +import zhttp.service.Client.{ClientRequest, ClientResponse} import zhttp.service.client.ClientSSLHandler.ClientSSLOptions import zhttp.service.client.{ClientChannelInitializer, ClientInboundHandler} import zio.{Chunk, Promise, Task, ZIO} @@ -23,7 +23,7 @@ import java.net.{InetAddress, InetSocketAddress} final case class Client(rtm: HttpRuntime[Any], cf: JChannelFactory[Channel], el: JEventLoopGroup) extends HttpMessageCodec { def request( - request: Client.ClientParams, + request: Client.ClientRequest, sslOption: ClientSSLOptions = ClientSSLOptions.DefaultSSL, ): Task[Client.ClientResponse] = for { @@ -33,7 +33,7 @@ final case class Client(rtm: HttpRuntime[Any], cf: JChannelFactory[Channel], el: } yield res private def asyncRequest( - req: ClientParams, + req: ClientRequest, promise: Promise[Throwable, ClientResponse], sslOption: ClientSSLOptions, ): Unit = { @@ -111,14 +111,14 @@ object Client { method: Method, url: URL, ): ZIO[EventLoopGroup with ChannelFactory, Throwable, ClientResponse] = - request(ClientParams(method, url)) + request(ClientRequest(method, url)) def request( method: Method, url: URL, sslOptions: ClientSSLOptions, ): ZIO[EventLoopGroup with ChannelFactory, Throwable, ClientResponse] = - request(ClientParams(method, url), sslOptions) + request(ClientRequest(method, 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(ClientRequest(method, url, headers), sslOptions) def request( method: Method, @@ -134,26 +134,26 @@ object Client { headers: Headers, content: HttpData, ): ZIO[EventLoopGroup with ChannelFactory, Throwable, ClientResponse] = - request(ClientParams(method, url, headers, content)) + request(ClientRequest(method, url, headers, content)) def request( - req: ClientParams, + req: ClientRequest, ): ZIO[EventLoopGroup with ChannelFactory, Throwable, ClientResponse] = make.flatMap(_.request(req)) def request( - req: ClientParams, + req: ClientRequest, sslOptions: ClientSSLOptions, ): ZIO[EventLoopGroup with ChannelFactory, Throwable, ClientResponse] = make.flatMap(_.request(req, sslOptions)) - final case class ClientParams( + final case class ClientRequest( method: Method, url: URL, getHeaders: Headers = Headers.empty, data: HttpData = HttpData.empty, private val channelContext: ChannelHandlerContext = null, - ) extends HeaderExtension[ClientParams] { self => + ) extends HeaderExtension[ClientRequest] { self => def getBodyAsString: Option[String] = data match { case HttpData.Text(text, _) => Some(text) @@ -172,7 +172,7 @@ object Client { /** * Updates the headers using the provided function */ - override def updateHeaders(update: Headers => Headers): ClientParams = + override def updateHeaders(update: Headers => Headers): ClientRequest = self.copy(getHeaders = update(self.getHeaders)) } diff --git a/zio-http/src/main/scala/zhttp/service/EncodeClientParams.scala b/zio-http/src/main/scala/zhttp/service/EncodeClientParams.scala index bf6955cdbd..efa935bbce 100644 --- a/zio-http/src/main/scala/zhttp/service/EncodeClientParams.scala +++ b/zio-http/src/main/scala/zhttp/service/EncodeClientParams.scala @@ -8,7 +8,7 @@ trait EncodeClientParams { /** * Converts client params to JFullHttpRequest */ - def encodeClientParams(jVersion: HttpVersion, req: Client.ClientParams): FullHttpRequest = { + def encodeClientParams(jVersion: HttpVersion, req: Client.ClientRequest): FullHttpRequest = { val method = req.method.asHttpMethod val uri = req.url.asString val content = req.getBodyAsString match { diff --git a/zio-http/src/test/scala/zhttp/http/EncodeClientParamsSpec.scala b/zio-http/src/test/scala/zhttp/http/EncodeClientRequestSpec.scala similarity index 88% rename from zio-http/src/test/scala/zhttp/http/EncodeClientParamsSpec.scala rename to zio-http/src/test/scala/zhttp/http/EncodeClientRequestSpec.scala index d97b87d458..47e007098c 100644 --- a/zio-http/src/test/scala/zhttp/http/EncodeClientParamsSpec.scala +++ b/zio-http/src/test/scala/zhttp/http/EncodeClientRequestSpec.scala @@ -7,15 +7,15 @@ import zio.random.Random import zio.test.Assertion._ import zio.test._ -object EncodeClientParamsSpec extends DefaultRunnableSpec with EncodeClientParams { +object EncodeClientRequestSpec extends DefaultRunnableSpec with EncodeClientParams { - val anyClientParam: Gen[Random with Sized, Client.ClientParams] = HttpGen.clientParams( + val anyClientParam: Gen[Random with Sized, Client.ClientRequest] = HttpGen.clientParams( HttpGen.httpData( Gen.listOf(Gen.alphaNumericString), ), ) - def clientParamWithFiniteData(size: Int): Gen[Random with Sized, Client.ClientParams] = HttpGen.clientParams( + def clientParamWithFiniteData(size: Int): Gen[Random with Sized, Client.ClientRequest] = HttpGen.clientParams( for { content <- Gen.alphaNumericStringBounded(size, size) data <- Gen.fromIterable(List(HttpData.fromString(content))) diff --git a/zio-http/src/test/scala/zhttp/http/GetBodyAsStringSpec.scala b/zio-http/src/test/scala/zhttp/http/GetBodyAsStringSpec.scala index 71dfd8d831..aad22542d1 100644 --- a/zio-http/src/test/scala/zhttp/http/GetBodyAsStringSpec.scala +++ b/zio-http/src/test/scala/zhttp/http/GetBodyAsStringSpec.scala @@ -18,7 +18,7 @@ object GetBodyAsStringSpec extends DefaultRunnableSpec { check(charsetGen) { charset => val encoded = Client - .ClientParams( + .ClientRequest( Method.GET, URL(Path("/")), getHeaders = Headers(HttpHeaderNames.CONTENT_TYPE.toString, s"text/html; charset=$charset"), @@ -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.ClientRequest(Method.GET, 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 d71c0238ca..feefb1182a 100644 --- a/zio-http/src/test/scala/zhttp/internal/HttpGen.scala +++ b/zio-http/src/test/scala/zhttp/internal/HttpGen.scala @@ -2,7 +2,7 @@ package zhttp.internal import io.netty.buffer.Unpooled import zhttp.http._ -import zhttp.service.Client.ClientParams +import zhttp.service.Client.ClientRequest import zio.random.Random import zio.stream.ZStream import zio.test.{Gen, Sized} @@ -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 ClientRequest(method, url, headers, 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 ClientRequest(method, url, headers, 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 93de634c9a..5745b2e662 100644 --- a/zio-http/src/test/scala/zhttp/internal/HttpRunnableSpec.scala +++ b/zio-http/src/test/scala/zhttp/internal/HttpRunnableSpec.scala @@ -37,7 +37,7 @@ abstract class HttpRunnableSpec extends DefaultRunnableSpec { self => port <- DynamicServer.getPort data = HttpData.fromString(content) response <- Client.request( - Client.ClientParams(method, URL(path, Location.Absolute(Scheme.HTTP, "localhost", port)), headers, data), + Client.ClientRequest(method, URL(path, Location.Absolute(Scheme.HTTP, "localhost", port)), headers, data), ClientSSLOptions.DefaultSSL, ) } yield response