- 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();content_copy
Configuring the WebServer in a configuration file
You can also define the configuration in a file.
WebServer configuration file
application.yamlserver:
port: 8080
bind-address: "0.0.0.0"content_copy
Then, in your application code, load the configuration from that file.
WebServer initialization using the
application.yaml file located on the classpathConfig config = Config.create();
WebServer webServer = WebServer.create(routing, config.get("server")); content_copy
application.yamlis a default configuration source loaded when YAML support is on classpath, so we can just useConfig.create()- Server expects the configuration tree located on the node of
server
Configuration options
See all configuration options here.
Available socket configuration options:
| Configuration key | Default value | Java type | Description | ||
|---|---|---|---|---|---|
port | int | Port to open server socket on, defaults to an available ephemeral port | |||
bind-address | all local addresses | String | Address to listen on (may be an IPV6 address as well) | ||
backlog | 1024 | int | Maximum length of the queue of incoming connections on the server socket. | ||
max-header-size | 16384 | int | Maximal number of bytes of all header values combined. Returns 400 if headers are bigger | ||
max-initial-line-length | 4096 | int | Maximal number of characters in the initial HTTP line. Returns 400 if line is longer | ||
timeout-millis | no timeout | long | Server socket timeout. | ||
receive-buffer-size | implementation default | int | Proposed value of the TCP receive window that is advertised to the remote peer on the server socket. | ||
name | @default for default socket | String | Name used for named sockets, to support additional server sockets (and their named routing) | ||
enabled | true | boolean | A socket can be disabled through configuration, in which case it is never opened | ||
max-chunk-size | 8192 | int | Maximal size of a chunk to read from incoming requests | ||
max-payload-size | -1 | long | Maximal size of a request payload in bytes. If exceeded a 413 error is returned. Negative value means no limit. | ||
connection-idle-timeout | 0 | int | Timeout seconds after which any idle connection will be automatically closed. 0 means no timeout. | ||
backpressure-buffer-size | long | 5242880 | Set 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-policy | String | LINEAR | Sets 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-headers | true | boolean | Whether to validate header names, if they contain illegal characters. | ||
initial-buffer-size | 128 | int | Initial size of buffer used to parse HTTP line and headers | ||
tls | Object | Configuration of TLS, please see our TLS example in repository | |||
requested-uri-discovery.enabled | boolean | true if types or trusted-proxies is set; false otherwise` | Sets whether requested URI discovery is enabled for the socket. | ||
requested-uri-discovery.trusted-proxies | AllowList | 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 otherwise | Assigns the front-end URI discovery type(s) this socket should use. This setting automatically enables discovery for the socket. |