From de9d9673d9e5765bd277f2ff3b0058465acd9cd1 Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Wed, 14 Jun 2023 11:38:50 +0300 Subject: [PATCH] [doc] Add HttpServer TLS Timeout Configuration section to reference documentation --- docs/asciidoc/http-server.adoc | 33 ++++++++++++++ .../server/security/custom/Application.java | 44 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 reactor-netty-examples/src/main/java/reactor/netty/examples/documentation/http/server/security/custom/Application.java diff --git a/docs/asciidoc/http-server.adoc b/docs/asciidoc/http-server.adoc index a5d211794f..1e252756b9 100644 --- a/docs/asciidoc/http-server.adoc +++ b/docs/asciidoc/http-server.adoc @@ -678,3 +678,36 @@ include::{examplesdir}/uds/Application.java[lines=18..33] ---- <1> Specifies `DomainSocketAddress` that will be used ==== + +== Timeout Configuration +This section describes various timeout configuration options that can be used in `HttpServer`. +Configuring a proper timeout may improve or solve issues in the communication process. +The configuration options can be grouped as follows: + +* <> + +[[http-server-ssl-tls-timeout]] +=== SSL/TLS Timeout +`HttpServer` supports the SSL/TLS functionality provided by Netty. + +The following list describes the available timeout configuration options: + +* `handshakeTimeout` - Use this option to configure the SSL handshake timeout (resolution: ms). Default: 10s. + +NOTE: You should consider increasing the SSL handshake timeout when expecting slow network connections. + +* `closeNotifyFlushTimeout` - Use this option to configure the SSL `close_notify` flush timeout (resolution: ms). Default: 3s. +* `closeNotifyReadTimeout` - Use this option to configure the SSL `close_notify` read timeout (resolution: ms). Default: 0s. + +To customize the default settings, you can configure `HttpServer` as follows: + +==== +[source,java,indent=0] +.{examplesdir}/security/custom/Application.java +---- +include::{examplesdir}/security/custom/Application.java[lines=18..44] +---- +<1> Configures the SSL handshake timeout to 30 seconds. +<2> Configures the SSL `close_notify` flush timeout to 10 seconds. +<3> Configures the SSL `close_notify` read timeout to 10 seconds. +==== diff --git a/reactor-netty-examples/src/main/java/reactor/netty/examples/documentation/http/server/security/custom/Application.java b/reactor-netty-examples/src/main/java/reactor/netty/examples/documentation/http/server/security/custom/Application.java new file mode 100644 index 0000000000..56b08edfc1 --- /dev/null +++ b/reactor-netty-examples/src/main/java/reactor/netty/examples/documentation/http/server/security/custom/Application.java @@ -0,0 +1,44 @@ +/* + * 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.security.custom; + +import reactor.netty.DisposableServer; +import reactor.netty.http.Http11SslContextSpec; +import reactor.netty.http.server.HttpServer; + +import java.io.File; +import java.time.Duration; + +public class Application { + + public static void main(String[] args) { + File cert = new File("certificate.crt"); + File key = new File("private.key"); + + Http11SslContextSpec http11SslContextSpec = Http11SslContextSpec.forServer(cert, key); + + DisposableServer server = + HttpServer.create() + .secure(spec -> spec.sslContext(http11SslContextSpec) + .handshakeTimeout(Duration.ofSeconds(30)) //<1> + .closeNotifyFlushTimeout(Duration.ofSeconds(10)) //<2> + .closeNotifyReadTimeout(Duration.ofSeconds(10))) //<3> + .bindNow(); + + server.onDispose() + .block(); + } +} \ No newline at end of file