Skip to content

Commit

Permalink
Merge branch 'main' into feat/websocket-client-support-0
Browse files Browse the repository at this point in the history
# Conflicts:
#	zio-http/src/main/scala/zhttp/http/Response.scala
#	zio-http/src/main/scala/zhttp/http/URL.scala
#	zio-http/src/main/scala/zhttp/service/Client.scala
#	zio-http/src/test/scala/zhttp/http/GetBodyAsStringSpec.scala
#	zio-http/src/test/scala/zhttp/internal/HttpRunnableSpec.scala
  • Loading branch information
tusharmath committed Feb 2, 2022
2 parents 7bb1643 + 21cdee6 commit 99a5fec
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 251 deletions.
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.3.3
version = 3.4.0
maxColumn = 120

align.preset = more
Expand Down
232 changes: 0 additions & 232 deletions BENCHMARKS.md

This file was deleted.

1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Check out the full documentation here: [Documentation]
- [ZIO Http](#zio-http)
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Benchmarks](#benchmarks)
- [Documentation](https://dream11.github.io/zio-http/)

# Getting Started
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ object Main extends App {
Server.error(_ => UIO.unit) ++
Server.keepAlive ++
Server.disableLeakDetection ++
Server.consolidateFlush
Server.consolidateFlush ++
Server.disableFlowControl

}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.6.1
sbt.version=1.6.2
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zhttp/http/Response.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ final case class Response private (
/**
* Wraps the current response as a Http
*/
def wrapHttp: Http[Any, Nothing, Any, Response] = Http.succeed(self)
def toHttp: Http[Any, Nothing, Any, Response] = Http.succeed(self)

/**
* Wraps the current response into a ZIO
Expand Down
6 changes: 4 additions & 2 deletions zio-http/src/main/scala/zhttp/service/Client.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ object Client {
final case class ClientRequest(
url: URL,
method: Method = Method.GET,
getHeaders: Headers = Headers.empty,
headers: Headers = Headers.empty,
private[zhttp] val data: HttpData = HttpData.empty,
private[zhttp] val attribute: Attribute = Attribute.empty,
private val channelContext: ChannelHandlerContext = null,
Expand All @@ -174,6 +174,8 @@ object Client {

def getBodyAsString: Task[String] = getBodyAsByteBuf.map(_.toString(getHeaders.getCharset))

def getHeaders: Headers = headers

def remoteAddress: Option[InetAddress] = {
if (channelContext != null && channelContext.channel().remoteAddress().isInstanceOf[InetSocketAddress])
Some(channelContext.channel().remoteAddress().asInstanceOf[InetSocketAddress].getAddress)
Expand All @@ -185,7 +187,7 @@ object Client {
* Updates the headers using the provided function
*/
override def updateHeaders(update: Headers => Headers): ClientRequest =
self.copy(getHeaders = update(self.getHeaders))
self.copy(headers = update(self.getHeaders))

private[zhttp] def getBodyAsByteBuf: Task[ByteBuf] = data.toByteBuf
}
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/main/scala/zhttp/service/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ object Server {
acceptContinue: Boolean = false,
keepAlive: Boolean = false,
consolidateFlush: Boolean = false,
flowControl: Boolean = false,
flowControl: Boolean = true,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ object GetBodyAsStringSpec extends DefaultRunnableSpec {
val request = Client
.ClientRequest(
URL(!!),
getHeaders = Headers.contentType(s"text/html; charset=$charset"),
headers = Headers.contentType(s"text/html; charset=$charset"),
data = HttpData.BinaryChunk(Chunk.fromArray("abc".getBytes(charset))),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package zhttp.http

import zio.test.Assertion._
import zio.test._

object ResponseHelpersSpec extends DefaultRunnableSpec {
val redirectSpec = {
val location = "www.google.com"
suite("redirectSpec")(
object ResponseSpec extends DefaultRunnableSpec {
def spec = suite("Response")(
suite("redirect") {
val location = "www.google.com"
test("Temporary redirect should produce a response with a TEMPORARY_REDIRECT") {
val x = Response.redirect(location)
assertTrue(x.status == Status.TEMPORARY_REDIRECT) &&
Expand All @@ -22,14 +23,19 @@ object ResponseHelpersSpec extends DefaultRunnableSpec {
test("Permanent redirect should produce a response with a location") {
val x = Response.redirect(location, true)
assertTrue(x.getHeaderValue(HeaderNames.location).contains(location))
} +
}
} +
suite("json")(
test("Json should set content type to ApplicationJson") {
val x = Response.json("""{"message": "Hello"}""")
assertTrue(x.getHeaderValue(HeaderNames.contentType).contains(HeaderValues.applicationJson.toString))
},
)
}

def spec =
suite("ResponseHelpers")(redirectSpec)
) +
suite("toHttp")(
testM("should convert response to Http") {
val http = Response.ok.toHttp
assertM(http(()))(equalTo(Response.ok))
},
),
)
}

1 comment on commit 99a5fec

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

Please sign in to comment.