Polish "Add server.netty.max-keep-alive-requests"

See gh-28875
This commit is contained in:
Stephane Nicoll 2022-01-04 10:25:39 +01:00
parent 0e94b2ce6e
commit 076ddc8579
4 changed files with 19 additions and 26 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Victor Mandujano
* @author Chris Bono * @author Chris Bono
* @author Parviz Rozikov * @author Parviz Rozikov
* @author Leo Li
* @since 1.0.0 * @since 1.0.0
*/ */
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true) @ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
@ -1341,6 +1340,12 @@ public class ServerProperties {
*/ */
private DataSize maxInitialLineLength = DataSize.ofKilobytes(4); 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. * Whether to validate headers when decoding requests.
*/ */
@ -1352,11 +1357,6 @@ public class ServerProperties {
*/ */
private Duration idleTimeout; private Duration idleTimeout;
/**
* Maximum number of requests that can be made per connection.
*/
private int maxKeepAliveRequests = -1;
public Duration getConnectionTimeout() { public Duration getConnectionTimeout() {
return this.connectionTimeout; return this.connectionTimeout;
} }
@ -1397,6 +1397,14 @@ public class ServerProperties {
this.maxInitialLineLength = maxInitialLineLength; this.maxInitialLineLength = maxInitialLineLength;
} }
public Integer getMaxKeepAliveRequests() {
return this.maxKeepAliveRequests;
}
public void setMaxKeepAliveRequests(Integer maxKeepAliveRequests) {
this.maxKeepAliveRequests = maxKeepAliveRequests;
}
public boolean isValidateHeaders() { public boolean isValidateHeaders() {
return this.validateHeaders; return this.validateHeaders;
} }
@ -1413,14 +1421,6 @@ public class ServerProperties {
this.idleTimeout = idleTimeout; this.idleTimeout = idleTimeout;
} }
public int getMaxKeepAliveRequests() {
return this.maxKeepAliveRequests;
}
public void setMaxKeepAliveRequests(int maxKeepAliveRequests) {
this.maxKeepAliveRequests = maxKeepAliveRequests;
}
} }
/** /**

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Brian Clozel
* @author Chentao Qu * @author Chentao Qu
* @author Artsiom Yudovin * @author Artsiom Yudovin
* @author Leo Li
* @since 2.1.0 * @since 2.1.0
*/ */
public class NettyWebServerFactoryCustomizer public class NettyWebServerFactoryCustomizer
@ -63,7 +62,7 @@ public class NettyWebServerFactoryCustomizer
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout)); .to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
propertyMapper.from(nettyProperties::getIdleTimeout).whenNonNull() propertyMapper.from(nettyProperties::getIdleTimeout).whenNonNull()
.to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout)); .to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
propertyMapper.from(nettyProperties::getMaxKeepAliveRequests).whenNonNull() propertyMapper.from(nettyProperties::getMaxKeepAliveRequests)
.to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests)); .to((maxKeepAliveRequests) -> customizeMaxKeepAliveRequests(factory, maxKeepAliveRequests));
customizeRequestDecoder(factory, propertyMapper); customizeRequestDecoder(factory, propertyMapper);
} }

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Rafiullah Hamedy
* @author Chris Bono * @author Chris Bono
* @author Parviz Rozikov * @author Parviz Rozikov
* @author Leo Li
*/ */
class ServerPropertiesTests { class ServerPropertiesTests {
@ -346,11 +345,6 @@ class ServerPropertiesTests {
assertThat(this.properties.getNetty().getMaxKeepAliveRequests()).isEqualTo(100); assertThat(this.properties.getNetty().getMaxKeepAliveRequests()).isEqualTo(100);
} }
@Test
void testCustomizeNettyMaxKeepAliveRequestsDefault() {
assertThat(this.properties.getNetty().getMaxKeepAliveRequests()).isEqualTo(-1);
}
@Test @Test
void tomcatAcceptCountMatchesProtocolDefault() throws Exception { void tomcatAcceptCountMatchesProtocolDefault() throws Exception {
assertThat(this.properties.getTomcat().getAcceptCount()).isEqualTo(getDefaultProtocol().getAcceptCount()); assertThat(this.properties.getTomcat().getAcceptCount()).isEqualTo(getDefaultProtocol().getAcceptCount());

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.