Skip to content

Commit

Permalink
cleanup and remove ServerTime (#2413)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTriple authored Aug 29, 2023
1 parent 8182fd3 commit e0c02dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ private[zio] object NettyDriver {
ZLayer.succeed(
new AtomicReference[(HttpApp[Any], ZEnvironment[Any])]((HttpApp.empty, ZEnvironment.empty)),
),
ZLayer.succeed(ServerTime.make(1000.millis)),
NettyRuntime.live,
ServerChannelInitializer.layer,
ServerInboundHandler.live,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ private[zio] final case class ServerInboundHandler(
appRef: AppRef,
config: Server.Config,
runtime: NettyRuntime,
time: ServerTime,
)(implicit trace: Trace)
extends SimpleChannelInboundHandler[HttpObject](false) { self =>

Expand Down Expand Up @@ -93,7 +92,7 @@ private[zio] final case class ServerInboundHandler(
Exit.succeed(Response.fromThrowable(throwable))
} else
app(req)
if (!attemptImmediateWrite(ctx, exit, time)) {
if (!attemptImmediateWrite(ctx, exit)) {
writeResponse(ctx, env, exit, jReq)(releaseRequest)
} else {
releaseRequest()
Expand Down Expand Up @@ -139,7 +138,6 @@ private[zio] final case class ServerInboundHandler(
private def attemptFastWrite(
ctx: ChannelHandlerContext,
response: Response,
time: ServerTime,
): Boolean = {

def fastEncode(response: Response, bytes: Array[Byte]) = {
Expand All @@ -165,7 +163,6 @@ private[zio] final case class ServerInboundHandler(
ctx: ChannelHandlerContext,
response: Response,
jRequest: HttpRequest,
time: ServerTime,
): Option[Task[Unit]] = {
response.body match {
case WebsocketBody(socketApp) if response.status == Status.SwitchingProtocols =>
Expand All @@ -185,11 +182,10 @@ private[zio] final case class ServerInboundHandler(
private def attemptImmediateWrite(
ctx: ChannelHandlerContext,
exit: ZIO[Any, Response, Response],
time: ServerTime,
): Boolean = {
exit match {
case Exit.Success(response) if response ne null =>
attemptFastWrite(ctx, response, time)
attemptFastWrite(ctx, response)
case _ => false
}
}
Expand Down Expand Up @@ -292,7 +288,7 @@ private[zio] final case class ServerInboundHandler(

private def writeNotFound(ctx: ChannelHandlerContext, jReq: HttpRequest): Unit = {
val response = Response.notFound(jReq.uri())
attemptFastWrite(ctx, response, time)
attemptFastWrite(ctx, response)
}

private def writeResponse(
Expand All @@ -316,9 +312,9 @@ private[zio] final case class ServerInboundHandler(
}.flatMap { response =>
ZIO.attempt {
if (response ne null) {
val done = attemptFastWrite(ctx, response, time)
val done = attemptFastWrite(ctx, response)
if (!done)
attemptFullWrite(ctx, response, jReq, time)
attemptFullWrite(ctx, response, jReq)
else
None
} else {
Expand All @@ -329,7 +325,7 @@ private[zio] final case class ServerInboundHandler(
}
}.flatMap(_.getOrElse(ZIO.unit)).catchSomeCause { case cause =>
ZIO.attempt(
attemptFastWrite(ctx, withDefaultErrorResponse(cause.squash), time),
attemptFastWrite(ctx, withDefaultErrorResponse(cause.squash)),
)
}
}
Expand All @@ -350,7 +346,7 @@ private[zio] final case class ServerInboundHandler(
object ServerInboundHandler {

val live: ZLayer[
ServerTime with Server.Config with NettyRuntime with AppRef,
Server.Config with NettyRuntime with AppRef,
Nothing,
ServerInboundHandler,
] = {
Expand All @@ -360,9 +356,8 @@ object ServerInboundHandler {
appRef <- ZIO.service[AppRef]
rtm <- ZIO.service[NettyRuntime]
config <- ZIO.service[Server.Config]
time <- ZIO.service[ServerTime]

} yield ServerInboundHandler(appRef, config, rtm, time)
} yield ServerInboundHandler(appRef, config, rtm)
}
}

Expand Down
57 changes: 0 additions & 57 deletions zio-http/src/main/scala/zio/http/netty/server/ServerTime.scala

This file was deleted.

0 comments on commit e0c02dd

Please sign in to comment.