Skip to content

Commit

Permalink
[doc] Add HttpServer Connection Timeout Configuration section to refe…
Browse files Browse the repository at this point in the history
…rence documentation (#2833)
  • Loading branch information
violetagg authored Jun 14, 2023
1 parent 9097a05 commit 2479ff5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/asciidoc/http-server.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,31 @@ This section describes various timeout configuration options that can be used in
Configuring a proper timeout may improve or solve issues in the communication process.
The configuration options can be grouped as follows:

* <<http-server-connection-timeout>>
* <<http-server-ssl-tls-timeout>>

[[http-server-connection-timeout]]
=== Connection Timeout
The following listing shows all available connection timeout configuration options.

* `idleTimeout` - The maximum time (resolution: ms) that this connection stays opened and waits for HTTP request.
Once the timeout is reached, the connection is closed. By default,
{javadoc}/reactor/netty/http/server/HttpServer.html#idleTimeout-java.time.Duration-[`idleTimeout`] is not specified,
this indicates no timeout (i.e. infinite), which means the connection is closed only if one of the peers decides to close it explicitly.

NOTE: It is always a good practice to configure an idle timeout.

To customize the default settings, you can configure `HttpServer` as follows:

====
[source,java,indent=0]
.{examplesdir}/idle/timeout/Application.java
----
include::{examplesdir}/idle/timeout/Application.java[lines=18..35]
----
<1> Configures the default idle timeout to 1 second.
====

[[http-server-ssl-tls-timeout]]
=== SSL/TLS Timeout
`HttpServer` supports the SSL/TLS functionality provided by Netty.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023 VMware, Inc. or its affiliates, All Rights Reserved.
*
* 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
*
* https://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.
*/
package reactor.netty.examples.documentation.http.server.idle.timeout;

import reactor.netty.DisposableServer;
import reactor.netty.http.server.HttpServer;

import java.time.Duration;

public class Application {

public static void main(String[] args) {
DisposableServer server =
HttpServer.create()
.idleTimeout(Duration.ofSeconds(1)) //<1>
.bindNow();

server.onDispose()
.block();
}
}

0 comments on commit 2479ff5

Please sign in to comment.