Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: added option to modify server bootstrap #1210

Merged
merged 6 commits into from
Apr 22, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions zio-http/src/main/scala/zhttp/service/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ sealed trait Server[-R, +E] { self =>
case UnsafeChannelPipeline(init) => s.copy(channelInitializer = init)
case RequestDecompression(enabled, strict) => s.copy(requestDecompression = (enabled, strict))
case ObjectAggregator(maxRequestSize) => s.copy(objectAggregator = maxRequestSize)
case UnsafeServerbootstrap(init) => s.copy(serverbootstrapInitializer = init)
}

def make(implicit
Expand Down Expand Up @@ -125,6 +126,10 @@ sealed trait Server[-R, +E] { self =>
def withUnsafeChannelPipeline(unsafePipeline: ChannelPipeline => Unit): Server[R, E] =
Concat(self, UnsafeChannelPipeline(unsafePipeline))

/** Creates a new serverBoostrap with custom configs * */
zsfVishnu marked this conversation as resolved.
Show resolved Hide resolved
def withUnsafeServerBootstrap(unsafeServerbootstrap: ServerBootstrap => Unit): Server[R, E] =
Concat(self, UnsafeServerbootstrap(unsafeServerbootstrap))

/**
* Creates a new server with netty's HttpContentDecompressor to decompress
* Http requests (@see <a href =
Expand All @@ -140,7 +145,6 @@ sealed trait Server[-R, +E] { self =>
def withObjectAggregator(maxRequestSize: Int = Int.MaxValue): Server[R, E] =
Concat(self, ObjectAggregator(maxRequestSize))
}

object Server {
private[zhttp] final case class Config[-R, +E](
leakDetectionLevel: LeakDetectionLevel = LeakDetectionLevel.SIMPLE,
Expand All @@ -157,6 +161,7 @@ object Server {
channelInitializer: ChannelPipeline => Unit = null,
requestDecompression: (Boolean, Boolean) = (false, false),
objectAggregator: Int = -1,
serverbootstrapInitializer: ServerBootstrap => Unit = null,
) {
def useAggregator: Boolean = objectAggregator >= 0
}
Expand All @@ -179,6 +184,7 @@ object Server {
private final case class UnsafeChannelPipeline(init: ChannelPipeline => Unit) extends UServer
private final case class RequestDecompression(enabled: Boolean, strict: Boolean) extends UServer
private final case class ObjectAggregator(maxRequestSize: Int) extends UServer
private final case class UnsafeServerbootstrap(init: ServerBootstrap => Unit) extends UServer

def app[R, E](http: HttpApp[R, E]): Server[R, E] = Server.App(http)
def port(port: Int): UServer = Server.Address(new InetSocketAddress(port))
Expand All @@ -197,8 +203,9 @@ object Server {
val paranoidLeakDetection: UServer = LeakDetection(LeakDetectionLevel.PARANOID)
val disableKeepAlive: UServer = Server.KeepAlive(false)
val consolidateFlush: UServer = ConsolidateFlush(true)
def unsafePipeline(pipeline: ChannelPipeline => Unit): UServer = UnsafeChannelPipeline(pipeline)
def enableObjectAggregator(maxRequestSize: Int = Int.MaxValue): UServer = ObjectAggregator(maxRequestSize)
def unsafePipeline(pipeline: ChannelPipeline => Unit): UServer = UnsafeChannelPipeline(pipeline)
def enableObjectAggregator(maxRequestSize: Int = Int.MaxValue): UServer = ObjectAggregator(maxRequestSize)
def unsafeServerbootstrap(serverBootstrap: ServerBootstrap => Unit): UServer = UnsafeServerbootstrap(serverBootstrap)

/**
* Creates a server from a http app.
Expand Down