From 4b5ea8e6f041efee513a951d103ab060187badfa Mon Sep 17 00:00:00 2001 From: shrutiverma97 Date: Mon, 18 Apr 2022 10:40:50 +0530 Subject: [PATCH] sealed trait changed to case class --- zio-http/src/main/scala/zhttp/http/Http.scala | 4 ++-- .../src/main/scala/zhttp/service/Server.scala | 2 +- .../zhttp/service/ServerResponseWriter.scala | 21 +++++++------------ 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/zio-http/src/main/scala/zhttp/http/Http.scala b/zio-http/src/main/scala/zhttp/http/Http.scala index e965cf394e..3a79c8f5b8 100644 --- a/zio-http/src/main/scala/zhttp/http/Http.scala +++ b/zio-http/src/main/scala/zhttp/http/Http.scala @@ -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 diff --git a/zio-http/src/main/scala/zhttp/service/Server.scala b/zio-http/src/main/scala/zhttp/service/Server.scala index 98fd6278a8..74f62570c4 100644 --- a/zio-http/src/main/scala/zhttp/service/Server.scala +++ b/zio-http/src/main/scala/zhttp/service/Server.scala @@ -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) diff --git a/zio-http/src/main/scala/zhttp/service/ServerResponseWriter.scala b/zio-http/src/main/scala/zhttp/service/ServerResponseWriter.scala index fa60c134c0..0b81bb9097 100644 --- a/zio-http/src/main/scala/zhttp/service/ServerResponseWriter.scala +++ b/zio-http/src/main/scala/zhttp/service/ServerResponseWriter.scala @@ -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)) @@ -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 - } -}