Skip to content

Commit

Permalink
sealed trait changed to case class
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrutiVerma97 committed Apr 18, 2022
1 parent bdc902b commit 4b5ea8e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions zio-http/src/main/scala/zhttp/http/Http.scala
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,11 @@ object Http {
self =>

private[zhttp] def compile[R1 <: R](
handler: ServerResponseWriter[R1],
resWriter: ServerResponseWriter[R1],
)(implicit
evE: E <:< Throwable,
): ChannelHandler =
Handler(http.asInstanceOf[HttpApp[R1, Throwable]], handler)
Handler(http.asInstanceOf[HttpApp[R1, Throwable]], resWriter)

/**
* Patches the response produced by the app
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 @@ -249,7 +249,7 @@ object Server {
channelFactory <- ZManaged.access[ServerChannelFactory](_.get)
eventLoopGroup <- ZManaged.access[EventLoopGroup](_.get)
zExec <- HttpRuntime.sticky[R](eventLoopGroup).toManaged_
handler = ServerResponseWriter(zExec, settings, ServerTime.make)
handler = new ServerResponseWriter(zExec, settings, ServerTime.make)
reqHandler = settings.app.compile(handler)
init = ServerChannelInitializer(zExec, settings, reqHandler)
serverBootstrap = new ServerBootstrap().channelFactory(channelFactory).group(eventLoopGroup)
Expand Down
21 changes: 7 additions & 14 deletions zio-http/src/main/scala/zhttp/service/ServerResponseWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import zio.{UIO, ZIO}

import java.io.File

private[zhttp] trait ServerResponseWriter[R] {
private[zhttp] final class ServerResponseWriter[R](
runtime: HttpRuntime[R],
conf: Server.Config[R, Throwable],
serverTime: ServerTime,
) {
type Ctx = ChannelHandlerContext
val rt: HttpRuntime[R]
val config: Server.Config[R, Throwable]

def serverTime: ServerTime
val rt: HttpRuntime[R] = runtime
val config: Server.Config[R, Throwable] = conf

def write(msg: Response, jReq: HttpRequest)(implicit ctx: Ctx): Unit = {
ctx.write(encodeResponse(msg))
Expand Down Expand Up @@ -125,12 +127,3 @@ private[zhttp] trait ServerResponseWriter[R] {
} yield ()
}
}
object ServerResponseWriter {
def apply[R](runtime: HttpRuntime[R], conf: Server.Config[R, Throwable], st: ServerTime): ServerResponseWriter[R] =
new ServerResponseWriter[R]() {
override val rt: HttpRuntime[R] = runtime
override val config: Server.Config[R, Throwable] = conf

override def serverTime: ServerTime = st
}
}

1 comment on commit 4b5ea8e

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

Please sign in to comment.