WebServer Configuration

Configure the WebServer either programmatically, or by the Helidon configuration framework.

Configuring the WebServer in your code

The easiest way to configure the WebServer is in your application code.

WebServer webServer = WebServer.builder()
      .bindAddress(InetAddress.getLocalHost())
      .port(8080)
      .build();
Copied

Configuring the WebServer in a configuration file

You can also define the configuration in a file.

WebServer configuration file application.yaml
server:
  port: 8080
  bind-address: "0.0.0.0"
Copied

Then, in your application code, load the configuration from that file.

WebServer initialization using the application.yaml file located on the classpath
Config config = Config.create(); 
WebServer webServer = WebServer.create(routing, config.get("server")); 
Copied
  • application.yaml is a default configuration source loaded when YAML support is on classpath, so we can just use Config.create()
  • Server expects the configuration tree located on the node of server

Configuration options

See all configuration options here.

Available socket configuration options:

Configuration keyDefault valueJava typeDescription
port intPort to open server socket on, defaults to an available ephemeral port
bind-addressall local addressesStringAddress to listen on (may be an IPV6 address as well)
backlog1024intMaximum length of the queue of incoming connections on the server socket.
max-header-size16384intMaximal number of bytes of all header values combined. Returns 400 if headers are bigger
max-initial-line-length4096intMaximal number of characters in the initial HTTP line. Returns 400 if line is longer
timeout-millisno timeoutlongServer socket timeout.
receive-buffer-sizeimplementation defaultintProposed value of the TCP receive window that is advertised to the remote peer on the server socket.
name@default for default socketStringName used for named sockets, to support additional server sockets (and their named routing)
enabledtruebooleanA socket can be disabled through configuration, in which case it is never opened
max-chunk-size8192intMaximal size of a chunk to read from incoming requests
max-payload-size-1longMaximal size of a request payload in bytes. If exceeded a 413 error is returned. Negative value means no limit.
connection-idle-timeout0intTimeout seconds after which any idle connection will be automatically closed. 0 means no timeout.
backpressure-buffer-sizelong5242880Set a maximum length of the unflushed response data sending buffer can keep without applying backpressure. Depends on backpressure-policy what happens if max buffer size is reached.Default is 5*1024*1024 - 5Mb
backpressure-policyStringLINEARSets the strategy for applying backpressure to the reactive stream of response data.* LINEAR - Data chunks are requested one-by-one after previous data chunk has been written to Netty’s buffer, when backpressure-buffer-size watermark is reached, new chunks are not requested until buffer size decrease under the watermark value. * PREFETCH - After first data chunk arrives, expected number of chunks needed to fill the buffer up to watermark is calculated and requested. * AUTO_FLUSH - Data are requested one-by-one, in case buffer reaches watermark, no other data is requested and extra flush is initiated. * UNBOUNDED - No backpressure is applied, Long.MAX_VALUE(unbounded) is requested from upstream.Default is LINEAR
validate-headerstruebooleanWhether to validate header names, if they contain illegal characters.
initial-buffer-size128intInitial size of buffer used to parse HTTP line and headers
tls ObjectConfiguration of TLS, please see our TLS example in repository
requested-uri-discovery.enabledbooleantrue if types or trusted-proxies is set; false otherwise`Sets whether requested URI discovery is enabled for the socket.
requested-uri-discovery.trusted-proxiesAllowList Assigns the settings governing the acceptance and rejection of forwarded headers from incoming requests to this socket. This setting automatically enables discovery for the socket.
requested-uri-discovery.types(FORWARDED, X_FORWARDED, HOST) (See RequestedUriDiscoveryType)FORWARDED if discovery is enabled; none otherwiseAssigns the front-end URI discovery type(s) this socket should use. This setting automatically enables discovery for the socket.