Skip to content

Commit e9588ca

Browse files
ayudovinbclozel
authored andcommitted
Support server.connection-timeout for Netty server
1 parent c40e61c commit e9588ca

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizer.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

1717
package org.springframework.boot.autoconfigure.web.embedded;
1818

19+
import java.time.Duration;
20+
21+
import io.netty.channel.ChannelOption;
22+
1923
import org.springframework.boot.autoconfigure.web.ServerProperties;
2024
import org.springframework.boot.cloud.CloudPlatform;
2125
import org.springframework.boot.context.properties.PropertyMapper;
@@ -31,6 +35,7 @@
3135
*
3236
* @author Brian Clozel
3337
* @author Chentao Qu
38+
* @author Artsiom Yudovin
3439
* @since 2.1.0
3540
*/
3641
public class NettyWebServerFactoryCustomizer
@@ -60,6 +65,10 @@ public void customize(NettyReactiveWebServerFactory factory) {
6065
.asInt(DataSize::toBytes)
6166
.to((maxHttpRequestHeaderSize) -> customizeMaxHttpHeaderSize(factory,
6267
maxHttpRequestHeaderSize));
68+
propertyMapper.from(this.serverProperties::getConnectionTimeout).whenNonNull()
69+
.asInt(Duration::toMillis)
70+
.to((duration) -> customizeConnectionTimeOut(factory, duration));
71+
6372
}
6473

6574
private boolean getOrDeduceUseForwardHeaders(ServerProperties serverProperties,
@@ -78,4 +87,12 @@ private void customizeMaxHttpHeaderSize(NettyReactiveWebServerFactory factory,
7887
.maxHeaderSize(maxHttpHeaderSize)));
7988
}
8089

90+
private void customizeConnectionTimeOut(NettyReactiveWebServerFactory factory,
91+
int duration) {
92+
factory.addServerCustomizers((NettyServerCustomizer) (httpServer) -> httpServer
93+
.tcpConfiguration((tcpServer) -> tcpServer
94+
.bootstrap((serverBootstrap) -> serverBootstrap.childOption(
95+
ChannelOption.CONNECT_TIMEOUT_MILLIS, duration))));
96+
}
97+
8198
}

0 commit comments

Comments
 (0)