From 076ddc85798ef1b36d29bc0a443aad94fde1dc62 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 4 Jan 2022 10:25:39 +0100 Subject: [PATCH] Polish "Add server.netty.max-keep-alive-requests" See gh-28875 --- .../autoconfigure/web/ServerProperties.java | 30 +++++++++---------- .../NettyWebServerFactoryCustomizer.java | 5 ++-- .../web/ServerPropertiesTests.java | 8 +---- .../NettyWebServerFactoryCustomizerTests.java | 2 +- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java index ed10ef42ee..67eec8c266 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,7 +68,6 @@ import org.springframework.util.unit.DataSize; * @author Victor Mandujano * @author Chris Bono * @author Parviz Rozikov - * @author Leo Li * @since 1.0.0 */ @ConfigurationProperties(prefix = "server", ignoreUnknownFields = true) @@ -1341,6 +1340,12 @@ public class ServerProperties { */ private DataSize maxInitialLineLength = DataSize.ofKilobytes(4); + /** + * Maximum number of requests that can be made per connection. By default, a + * connection serves unlimited number of requests. + */ + private Integer maxKeepAliveRequests; + /** * Whether to validate headers when decoding requests. */ @@ -1352,11 +1357,6 @@ public class ServerProperties { */ private Duration idleTimeout; - /** - * Maximum number of requests that can be made per connection. - */ - private int maxKeepAliveRequests = -1; - public Duration getConnectionTimeout() { return this.connectionTimeout; } @@ -1397,6 +1397,14 @@ public class ServerProperties { this.maxInitialLineLength = maxInitialLineLength; } + public Integer getMaxKeepAliveRequests() { + return this.maxKeepAliveRequests; + } + + public void setMaxKeepAliveRequests(Integer maxKeepAliveRequests) { + this.maxKeepAliveRequests = maxKeepAliveRequests; + } + public boolean isValidateHeaders() { return this.validateHeaders; } @@ -1413,14 +1421,6 @@ public class ServerProperties { this.idleTimeout = idleTimeout; } - public int getMaxKeepAliveRequests() { - return this.maxKeepAliveRequests; - } - - public void setMaxKeepAliveRequests(int maxKeepAliveRequests) { - this.maxKeepAliveRequests = maxKeepAliveRequests; - } - } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizer.java index 51af7a45a9..1776b8c97b 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,6 @@ import org.springframework.core.env.Environment; * @author Brian Clozel * @author Chentao Qu * @author Artsiom Yudovin - * @author Leo Li * @since 2.1.0 */ public class NettyWebServerFactoryCustomizer @@ -63,7 +62,7 @@ public class NettyWebServerFactoryCustomizer .to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout)); propertyMapper.from(nettyProperties::getIdleTimeout).whenNonNull() .to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout)); - propertyMapper.from(nettyProperties::getMaxKeepAliveRequests).whenNonNull() + propertyMapper.from(nettyProperties::getMaxKeepAliveRequests) .to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests)); customizeRequestDecoder(factory, propertyMapper); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java index 489c2af8d4..8623ebb9eb 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,6 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Rafiullah Hamedy * @author Chris Bono * @author Parviz Rozikov - * @author Leo Li */ class ServerPropertiesTests { @@ -346,11 +345,6 @@ class ServerPropertiesTests { assertThat(this.properties.getNetty().getMaxKeepAliveRequests()).isEqualTo(100); } - @Test - void testCustomizeNettyMaxKeepAliveRequestsDefault() { - assertThat(this.properties.getNetty().getMaxKeepAliveRequests()).isEqualTo(-1); - } - @Test void tomcatAcceptCountMatchesProtocolDefault() throws Exception { assertThat(this.properties.getTomcat().getAcceptCount()).isEqualTo(getDefaultProtocol().getAcceptCount()); diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java index 6ef976dd19..9304603f38 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/NettyWebServerFactoryCustomizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.