Skip to content

Commit

Permalink
made httpVersion first param in ClientParams, made relevant changes
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 5488b57 commit d439e7d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions zio-http/src/main/scala/zhttp/service/Client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,30 +111,30 @@ 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,
url: URL,
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,
url: URL,
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,
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions zio-http/src/test/scala/zhttp/http/GetBodyAsStringSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
)
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions zio-http/src/test/scala/zhttp/internal/HttpGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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 {
file <- Gen.fromEffect(ZIO.succeed(new File(getClass.getResource("/TestFile.txt").getPath)))
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 {
Expand Down
10 changes: 5 additions & 5 deletions zio-http/src/test/scala/zhttp/internal/HttpRunnableSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

4 comments on commit d439e7d

@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: 831735.92

@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: 827526.19

@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: 848063.60

@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: 836722.83

Please sign in to comment.