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

chore: Support customize server and socket options of undertow #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
23 changes: 20 additions & 3 deletions cask/src/cask/main/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import cask.model._
import cask.router.{Decorator, EndpointMetadata, EntryPoint, Result}
import cask.util.Logger
import io.undertow.Undertow
import io.undertow.server.handlers.BlockingHandler
import io.undertow.server.{HttpHandler, HttpServerExchange}
import io.undertow.server.handlers.BlockingHandler
import io.undertow.util.HttpString
import org.xnio.Options

import java.util.concurrent.ExecutorService

Expand Down Expand Up @@ -83,12 +84,28 @@ abstract class Main{
Main.defaultHandleError(routes, metadata, e, debugMode, req)
}

/**
* Set server options for the undertow server. By default, no options are set.
* */
protected def serverOptions : List[(org.xnio.Option[_], Any)] = Nil

/**
* Set server options for the undertow server. By default, no options are set.
* */
protected def socketOptions : List[(org.xnio.Option[_], Any)] = Nil

def main(args: Array[String]): Unit = {
if (!verbose) Main.silenceJboss()
val server = Undertow.builder
val builder = Undertow.builder
.addHttpListener(port, host)
.setHandler(defaultHandler)
.build
serverOptions.foreach {
case (option: org.xnio.Option[Any @unchecked], value) => builder.setServerOption(option, value)
}
socketOptions.foreach {
case (option: org.xnio.Option[Any @unchecked], value) => builder.setSocketOption(option, value)
}
val server = builder.build()
server.start()
//register an on exit hook to stop the server
Runtime.getRuntime.addShutdownHook(new Thread(() => {
Expand Down
Loading