Skip to content

Commit 7f090b0

Browse files
committed
chore: Support customize server and socket options of undertow
1 parent 05ca192 commit 7f090b0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

cask/src/cask/main/Main.scala

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import cask.model._
66
import cask.router.{Decorator, EndpointMetadata, EntryPoint, Result}
77
import cask.util.Logger
88
import io.undertow.Undertow
9-
import io.undertow.server.handlers.BlockingHandler
109
import io.undertow.server.{HttpHandler, HttpServerExchange}
10+
import io.undertow.server.handlers.BlockingHandler
1111
import io.undertow.util.HttpString
12+
import org.xnio.Options
1213

1314
import java.util.concurrent.ExecutorService
1415

@@ -83,12 +84,28 @@ abstract class Main{
8384
Main.defaultHandleError(routes, metadata, e, debugMode, req)
8485
}
8586

87+
/**
88+
* Set server options for the undertow server. By default, no options are set.
89+
* */
90+
protected def serverOptions : List[(org.xnio.Option[_], Any)] = Nil
91+
92+
/**
93+
* Set server options for the undertow server. By default, no options are set.
94+
* */
95+
protected def socketOptions : List[(org.xnio.Option[_], Any)] = Nil
96+
8697
def main(args: Array[String]): Unit = {
8798
if (!verbose) Main.silenceJboss()
88-
val server = Undertow.builder
99+
val builder = Undertow.builder
89100
.addHttpListener(port, host)
90101
.setHandler(defaultHandler)
91-
.build
102+
serverOptions.foreach {
103+
case (option: org.xnio.Option[Any @unchecked], value) => builder.setServerOption(option, value)
104+
}
105+
socketOptions.foreach {
106+
case (option: org.xnio.Option[Any @unchecked], value) => builder.setSocketOption(option, value)
107+
}
108+
val server = builder.build()
92109
server.start()
93110
//register an on exit hook to stop the server
94111
Runtime.getRuntime.addShutdownHook(new Thread(() => {

0 commit comments

Comments
 (0)