///////////////////////////////////////////////////////////////////////////////

    Copyright (c) 2018, 2020 Oracle and/or its affiliates.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

///////////////////////////////////////////////////////////////////////////////

:javadoc-base-url-api: {javadoc-base-url}?io/helidon/webserver
:description: Helidon Reactive Webserver Configuration
:keywords: helidon, reactive, reactive streams, reactive java, reactive webserver

= WebServer Configuration

Configure the WebServer using the Helidon configuration framework, either programmatically 
or via a configuration file.

== Configuring the WebServer in your code

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

[source,java]
----
ServerConfiguration configuration = ServerConfiguration.builder()
                                                       .bindAddress(InetAddress.getLocalHost())
                                                       .port(8080)
                                                       .build();
WebServer webServer = WebServer.create(configuration, routing);
----

== Configuring the WebServer in a configuration file

You can also define the configuration in a file.

[source,hocon]
.WebServer configuration file `application.conf`
----
webserver {
  port: 8080,
  bind-address: "0.0.0.0",
}
----

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

[source,java]
.WebServer initialization using the `application.conf` file located on the classpath
----
ServerConfiguration configuration = ServerConfiguration.create(
        Config.builder()
              .sources(classpath("application.conf"))
              .build());

WebServer webServer = WebServer.create(configuration, routing);
----

== Configuration options

See all configuration options 
 link:{javadoc-base-url-api}/ServerConfiguration.html[here].

Available socket configuration options:
[cols="^2s,<2,<2,<6"]
|===
|Configuration key |Default value ^|Java type  ^|Description
|`port` |{nbsp} |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` |`8192` |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.
|`max-chunk-size` | `8192` |int |Maximal size of a chunk to read from incoming requests
|`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
|`ssl` |{nbsp} |Object |Configuration of SSL, please see our SSL example in repository
|===