java.lang.Object
io.jooby.ServerOptions
Available server options. To load server options from configuration files, just do:
Optional<ServerOptions> serverOptions = ServerOptions.from(getEnvironment().getConfig());
- Since:
- 2.0.0
- Author:
- edgar
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
10mb constant in bytes.static final int
16kb constant in bytes.static final int
4kb constant in bytes.static final int
8kb constant in bytes.static final int
Default compression level for gzip.static final int
Number of available threads, but never smaller than2
.static final int
Default application port8080
or the value of system propertyserver.port
.static final int
Default application secure port8443
or the value of system propertyserver.securePort
.static final int
Number of worker (a.k.a application) threads. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<ServerOptions>
from
(com.typesafe.config.Config conf) Creates server options from config object.int
Server buffer size in bytes.Indicates compression level to use while producing gzip responses.boolean
True if default headers:Date
,Content-Type
andServer
are enabled.getHost()
Server host, defaults is0.0.0.0
.int
Number of IO threads used by the server.int
getIoThreads
(int defaultIoThreads) Number of IO threads used by the server.int
Maximum request size in bytes.int
getPort()
Server HTTP port.HTTPs port ornull
.Server name.getSsl()
SSL options.getSSLContext
(ClassLoader loader) Creates SSL context using the given resource loader.int
Number of worker threads (a.k.a application) to use.int
getWorkerThreads
(int defaultWorkerThreads) Number of worker threads (a.k.a application) to use.Whenever 100-Expect and continue requests are handled by the server.isHttp2()
Specify when HTTP/2 is enabled or not.boolean
Bind only https port.boolean
True when SSL is enabled.setBufferSize
(int bufferSize) Set buffer size.setCompressionLevel
(Integer compressionLevel) Set compression level to use while producing gzip responses.setDefaultHeaders
(boolean defaultHeaders) Enabled/disabled default server headers:Date
,Content-Type
andServer
.setExpectContinue
(Boolean expectContinue) Set 100-Expect and continue requests are handled by the server.void
Set the server host, defaults to0.0.0.0
.Turn on/off HTTP/2 support.setHttpsOnly
(boolean httpsOnly) Bind only https port.setIoThreads
(int ioThreads) Set number of IO threads to use.setMaxRequestSize
(int maxRequestSize) Set max request size in bytes.setPort
(int port) Set the server port (default is 8080).setSecurePort
(Integer securePort) Set HTTPs port.Set server name.setSsl
(SslOptions ssl) Set SSL options.setWorkerThreads
(int workerThreads) Set number of worker threads (a.k.a application) to use.toString()
-
Field Details
-
SERVER_PORT
public static final int SERVER_PORTDefault application port8080
or the value of system propertyserver.port
. -
SEVER_SECURE_PORT
public static final int SEVER_SECURE_PORTDefault application secure port8443
or the value of system propertyserver.securePort
. -
DEFAULT_COMPRESSION_LEVEL
public static final int DEFAULT_COMPRESSION_LEVELDefault compression level for gzip.- See Also:
-
_4KB
public static final int _4KB4kb constant in bytes.- See Also:
-
_8KB
public static final int _8KB8kb constant in bytes.- See Also:
-
_16KB
public static final int _16KB16kb constant in bytes.- See Also:
-
_10MB
public static final int _10MB10mb constant in bytes.- See Also:
-
IO_THREADS
public static final int IO_THREADSNumber of available threads, but never smaller than2
. -
WORKER_THREADS
public static final int WORKER_THREADSNumber of worker (a.k.a application) threads. It is the number of processors multiply by8
.
-
-
Constructor Details
-
ServerOptions
public ServerOptions()
-
-
Method Details
-
from
Creates server options from config object. The configuration options must provided entries like:server.port
,server.ioThreads
, etc...- Parameters:
conf
- Configuration object.- Returns:
- Server options.
-
toString
-
setServer
Set server name.- Parameters:
server
- Name of the underlying server.- Returns:
- This options.
-
getServer
Server name.- Returns:
- Server name.
-
getPort
public int getPort()Server HTTP port.- Returns:
- Server HTTP port.
-
setPort
Set the server port (default is 8080). For random port use:0
.- Parameters:
port
- Server port or0
to pick a random port.- Returns:
- This options.
-
getSecurePort
HTTPs port ornull
.- Returns:
- HTTPs port or
null
.
-
isSSLEnabled
public boolean isSSLEnabled()True when SSL is enabled. Either bc the secure port or SSL options are set.- Returns:
- True when SSL is enabled. Either bc the secure port or SSL options are set.
-
setSecurePort
Set HTTPs port.- Parameters:
securePort
- Port number or0
for random number.- Returns:
- This options.
-
isHttpsOnly
public boolean isHttpsOnly()Bind only https port. Default is false.- Returns:
- True when only https is required.
-
setHttpsOnly
Bind only https port. Default is false.- Parameters:
httpsOnly
- True to bind only HTTPS.- Returns:
- This options.
-
getIoThreads
public int getIoThreads()Number of IO threads used by the server. Required by Netty and Undertow.- Returns:
- Number of IO threads used by the server. Required by Netty and Undertow.
-
getIoThreads
public int getIoThreads(int defaultIoThreads) Number of IO threads used by the server. Required by Netty and Undertow.- Parameters:
defaultIoThreads
- Default number of threads if none was set.- Returns:
- Number of IO threads used by the server. Required by Netty and Undertow.
-
setIoThreads
Set number of IO threads to use. Supported by Netty and Undertow.- Parameters:
ioThreads
- Number of threads. Must be greater than0
.- Returns:
- This options.
-
getWorkerThreads
public int getWorkerThreads()Number of worker threads (a.k.a application) to use. These are the threads which are allowed to block.- Returns:
- Number of worker threads (a.k.a application) to use. These are the threads which are allowed to block.
-
getWorkerThreads
public int getWorkerThreads(int defaultWorkerThreads) Number of worker threads (a.k.a application) to use. These are the threads which are allowed to block.- Parameters:
defaultWorkerThreads
- Default worker threads is none was set.- Returns:
- Number of worker threads (a.k.a application) to use. These are the threads which are allowed to block.
-
setWorkerThreads
Set number of worker threads (a.k.a application) to use. These are the threads which are allowed to block.- Parameters:
workerThreads
- Number of worker threads to use.- Returns:
- This options.
-
getCompressionLevel
Indicates compression level to use while producing gzip responses.- Returns:
- Compression level value between
0...9
ornull
when off.
-
setCompressionLevel
Set compression level to use while producing gzip responses.Gzip is off by default (compression level is null).
- Parameters:
compressionLevel
- Value between0..9
ornull
.- Returns:
- This options.
-
getDefaultHeaders
public boolean getDefaultHeaders()True if default headers:Date
,Content-Type
andServer
are enabled.- Returns:
- True if default headers:
Date
,Content-Type
andServer
are enabled.
-
setDefaultHeaders
Enabled/disabled default server headers:Date
,Content-Type
andServer
. Enabled by default.- Parameters:
defaultHeaders
- True for enabled.- Returns:
- This options.
-
getBufferSize
public int getBufferSize()Server buffer size in bytes. Default is:16kb
. Used for reading/writing data.- Returns:
- Server buffer size in bytes. Default is:
16kb
. Used for reading/writing data.
-
setBufferSize
Set buffer size.- Parameters:
bufferSize
- Buffer size.- Returns:
- This options.
-
getMaxRequestSize
public int getMaxRequestSize()Maximum request size in bytes. Request exceeding this value results inStatusCode.REQUEST_ENTITY_TOO_LARGE
response. Default is10mb
.- Returns:
- Maximum request size in bytes.
-
setMaxRequestSize
Set max request size in bytes.- Parameters:
maxRequestSize
- Max request size in bytes.- Returns:
- This options.
-
getHost
Server host, defaults is0.0.0.0
.- Returns:
- Server host, defaults is
0.0.0.0
.
-
setHost
Set the server host, defaults to0.0.0.0
.- Parameters:
host
- Server host. Localhost, null or empty values fallback to0.0.0.0
.
-
getSsl
SSL options.- Returns:
- SSL options.
-
setSsl
Set SSL options.- Parameters:
ssl
- SSL options.- Returns:
- Server options.
-
isHttp2
Specify when HTTP/2 is enabled or not. This value is set tonull
, which allows Jooby to enabled by default when dependency is added it.To turn off set to false.
- Returns:
- Whenever HTTP/2 is enabled.
-
setHttp2
Turn on/off HTTP/2 support.- Parameters:
http2
- True to enabled.- Returns:
- This options.
-
isExpectContinue
Whenever 100-Expect and continue requests are handled by the server. This is off by default, except for Jetty which is always ON.- Returns:
- True when enabled.
-
setExpectContinue
Set 100-Expect and continue requests are handled by the server. This is off by default, except for Jetty which is always ON.- Parameters:
expectContinue
- True or false.- Returns:
- This options.
-
getSSLContext
Creates SSL context using the given resource loader. This method attempts to create a SSLContext when one of the following is true:getSecurePort()
has been setgetSsl()
has been set.
If secure port is set and there is no SSL options, this method configure a SSL context using the a self-signed certificate for
localhost
.If
SslOptions.getSslContext()
is set, it is returned without modification.- Parameters:
loader
- Resource loader.- Returns:
- SSLContext or
null
when SSL is disabled.
-