Skip to content

Commit

Permalink
in EncodeClientParams use http version from ClientParams
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumant Awasthi authored and Sumant Awasthi committed Jan 12, 2022
1 parent d439e7d commit d5656e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zhttp/service/Client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final case class Client(rtm: HttpRuntime[Any], cf: JChannelFactory[Channel], el:
promise: Promise[Throwable, ClientResponse],
sslOption: ClientSSLOptions,
): Unit = {
val jReq = encodeClientParams(req.httpVersion, req)
val jReq = encodeClientParams(req)
try {
val hand = ClientInboundHandler(rtm, jReq, promise)
val host = req.url.host
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package zhttp.service

import io.netty.buffer.Unpooled
import io.netty.handler.codec.http.{DefaultFullHttpRequest, FullHttpRequest, HttpHeaderNames, HttpVersion}
import io.netty.handler.codec.http.{DefaultFullHttpRequest, FullHttpRequest, HttpHeaderNames}
import zhttp.http.HTTP_CHARSET
trait EncodeClientParams {

/**
* Converts client params to JFullHttpRequest
*/
def encodeClientParams(jVersion: HttpVersion, req: Client.ClientParams): FullHttpRequest = {
def encodeClientParams(req: Client.ClientParams): FullHttpRequest = {
val method = req.method.asHttpMethod
val uri = req.url.asString
val content = req.getBodyAsString match {
Expand All @@ -21,7 +21,7 @@ trait EncodeClientParams {
headers.set(HttpHeaderNames.CONTENT_LENGTH, writerIndex.toString())
}
// TODO: we should also add a default user-agent req header as some APIs might reject requests without it.
val jReq = new DefaultFullHttpRequest(jVersion, method, uri, content)
val jReq = new DefaultFullHttpRequest(req.httpVersion, method, uri, content)
jReq.headers().set(headers)

jReq
Expand Down
12 changes: 6 additions & 6 deletions zio-http/src/test/scala/zhttp/http/EncodeClientParamsSpec.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package zhttp.http

import io.netty.handler.codec.http.{HttpHeaderNames, HttpVersion}
import io.netty.handler.codec.http.HttpHeaderNames
import zhttp.internal.HttpGen
import zhttp.service.{Client, EncodeClientParams}
import zio.random.Random
Expand All @@ -25,31 +25,31 @@ object EncodeClientParamsSpec extends DefaultRunnableSpec with EncodeClientParam
def spec = suite("EncodeClientParams") {
testM("method") {
check(anyClientParam) { params =>
val req = encodeClientParams(HttpVersion.HTTP_1_1, params)
val req = encodeClientParams(params)
assert(req.method())(equalTo(params.method.asHttpMethod))
}
} +
testM("method on HttpData.File") {
check(HttpGen.clientParamsForFileHttpData()) { params =>
val req = encodeClientParams(HttpVersion.HTTP_1_1, params)
val req = encodeClientParams(params)
assert(req.method())(equalTo(params.method.asHttpMethod))
}
} +
testM("uri") {
check(anyClientParam) { params =>
val req = encodeClientParams(HttpVersion.HTTP_1_1, params)
val req = encodeClientParams(params)
assert(req.uri())(equalTo(params.url.asString))
}
} +
testM("uri on HttpData.File") {
check(HttpGen.clientParamsForFileHttpData()) { params =>
val req = encodeClientParams(HttpVersion.HTTP_1_1, params)
val req = encodeClientParams(params)
assert(req.uri())(equalTo(params.url.asString))
}
} +
testM("content-length") {
check(clientParamWithFiniteData(5)) { params =>
val req = encodeClientParams(HttpVersion.HTTP_1_1, params)
val req = encodeClientParams(params)
assert(req.headers().getInt(HttpHeaderNames.CONTENT_LENGTH).toLong)(equalTo(5L))
}
}
Expand Down

1 comment on commit d5656e7

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 Performance Benchmark:

Concurrency: 256
Requests/sec: 800649.02

Please sign in to comment.