Remove deprecated configuration properties

This commit removes the following deprecated properties:

* `server.connection-timeout`
* `server.use-forward-headers`
* `server.jetty.max-http-post-size`
* `server.tomcat.max-http-post-size`

Closes gh-20991
This commit is contained in:
Stephane Nicoll 2020-04-19 15:49:05 +02:00
parent 7ab2bca376
commit 5afe4743cb
12 changed files with 42 additions and 140 deletions

View File

@ -100,13 +100,6 @@ public class ServerProperties {
*/
private DataSize maxHttpHeaderSize = DataSize.ofKilobytes(8);
/**
* Time that connectors wait for another HTTP request before closing the connection.
* When not set, the connector's container-specific default is used. Use a value of -1
* to indicate no (that is, an infinite) timeout.
*/
private Duration connectionTimeout;
@NestedConfigurationProperty
private Ssl ssl;
@ -145,17 +138,6 @@ public class ServerProperties {
this.address = address;
}
@DeprecatedConfigurationProperty(reason = "replaced to support additional strategies",
replacement = "server.forward-headers-strategy")
public Boolean isUseForwardHeaders() {
return ForwardHeadersStrategy.NATIVE.equals(this.forwardHeadersStrategy);
}
public void setUseForwardHeaders(Boolean useForwardHeaders) {
this.forwardHeadersStrategy = Boolean.TRUE.equals(useForwardHeaders) ? ForwardHeadersStrategy.NATIVE
: ForwardHeadersStrategy.NONE;
}
public String getServerHeader() {
return this.serverHeader;
}
@ -172,18 +154,6 @@ public class ServerProperties {
this.maxHttpHeaderSize = maxHttpHeaderSize;
}
@Deprecated
@DeprecatedConfigurationProperty(
reason = "Each server behaves differently. Use server specific properties instead.")
public Duration getConnectionTimeout() {
return this.connectionTimeout;
}
@Deprecated
public void setConnectionTimeout(Duration connectionTimeout) {
this.connectionTimeout = connectionTimeout;
}
public ErrorProperties getError() {
return this.error;
}
@ -443,17 +413,6 @@ public class ServerProperties {
this.getThreads().setMinSpare(minSpareThreads);
}
@Deprecated
@DeprecatedConfigurationProperty(replacement = "server.tomcat.max-http-form-post-size")
public DataSize getMaxHttpPostSize() {
return this.maxHttpFormPostSize;
}
@Deprecated
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
this.maxHttpFormPostSize = maxHttpPostSize;
}
public DataSize getMaxHttpFormPostSize() {
return this.maxHttpFormPostSize;
}
@ -1084,17 +1043,6 @@ public class ServerProperties {
return this.threads;
}
@Deprecated
@DeprecatedConfigurationProperty(replacement = "server.jetty.max-http-form-post-size")
public DataSize getMaxHttpPostSize() {
return this.maxHttpFormPostSize;
}
@Deprecated
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
this.maxHttpFormPostSize = maxHttpPostSize;
}
public DataSize getMaxHttpFormPostSize() {
return this.maxHttpFormPostSize;
}

View File

@ -87,8 +87,6 @@ public class JettyWebServerFactoryCustomizer
.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
propertyMapper.from(jettyProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when(this::isPositive)
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
propertyMapper.from(properties::getConnectionTimeout).whenNonNull()
.to((connectionTimeout) -> customizeIdleTimeout(factory, connectionTimeout));
propertyMapper.from(jettyProperties::getConnectionIdleTimeout).whenNonNull()
.to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
propertyMapper.from(jettyProperties::getAccesslog).when(ServerProperties.Jetty.Accesslog::isEnabled)

View File

@ -60,8 +60,6 @@ public class NettyWebServerFactoryCustomizer
PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
propertyMapper.from(this.serverProperties::getMaxHttpHeaderSize)
.to((maxHttpRequestHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpRequestHeaderSize));
propertyMapper.from(this.serverProperties::getConnectionTimeout)
.to((connectionTimeout) -> customizeGenericConnectionTimeout(factory, connectionTimeout));
ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
propertyMapper.from(nettyProperties::getConnectionTimeout).whenNonNull()
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
@ -80,14 +78,6 @@ public class NettyWebServerFactoryCustomizer
(httpRequestDecoderSpec) -> httpRequestDecoderSpec.maxHeaderSize((int) maxHttpHeaderSize.toBytes())));
}
private void customizeGenericConnectionTimeout(NettyReactiveWebServerFactory factory, Duration connectionTimeout) {
if (!connectionTimeout.isZero()) {
long timeoutMillis = connectionTimeout.isNegative() ? 0 : connectionTimeout.toMillis();
factory.addServerCustomizers((httpServer) -> httpServer.tcpConfiguration((tcpServer) -> tcpServer
.selectorOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) timeoutMillis)));
}
}
private void customizeConnectionTimeout(NettyReactiveWebServerFactory factory, Duration connectionTimeout) {
factory.addServerCustomizers((httpServer) -> httpServer.tcpConfiguration((tcpServer) -> tcpServer
.selectorOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) connectionTimeout.toMillis())));

View File

@ -100,8 +100,6 @@ public class TomcatWebServerFactoryCustomizer
propertyMapper.from(tomcatProperties::getAccesslog).when(ServerProperties.Tomcat.Accesslog::isEnabled)
.to((enabled) -> customizeAccessLog(factory));
propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding);
propertyMapper.from(properties::getConnectionTimeout).whenNonNull()
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
propertyMapper.from(tomcatProperties::getConnectionTimeout).whenNonNull()
.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
propertyMapper.from(tomcatProperties::getMaxConnections).when(this::isPositive)

View File

@ -78,8 +78,6 @@ public class UndertowWebServerFactoryCustomizer
ServerProperties properties = this.serverProperties;
map.from(properties::getMaxHttpHeaderSize).asInt(DataSize::toBytes).when(this::isPositive)
.to(options.server(UndertowOptions.MAX_HEADER_SIZE));
map.from(properties::getConnectionTimeout).asInt(Duration::toMillis)
.to(options.server(UndertowOptions.NO_REQUEST_TIMEOUT));
mapUndertowProperties(factory, options);
mapAccessLogProperties(factory);
map.from(this::getOrDeduceUseForwardHeaders).to(factory::setUseForwardHeaders);

View File

@ -29,6 +29,14 @@
"level": "error"
}
},
{
"name": "server.connection-timeout",
"type" : "java.time.Duration",
"deprecation": {
"reason": "Each server behaves differently. Use server specific properties instead.",
"level": "error"
}
},
{
"name": "server.jetty.accesslog.date-format",
"deprecation": {
@ -119,6 +127,14 @@
"description": "Whether to enable HTTP/2 support, if the current environment supports it.",
"defaultValue": false
},
{
"name": "server.jetty.max-http-post-size",
"type": "org.springframework.util.unit.DataSize",
"deprecation": {
"replacement": "server.jetty.max-http-form-post-size",
"level": "error"
}
},
{
"name": "server.port",
"defaultValue": 8080
@ -245,6 +261,23 @@
"name": "server.ssl.trust-store-type",
"description": "Type of the trust store."
},
{
"name": "server.tomcat.max-http-post-size",
"type": "org.springframework.util.unit.DataSize",
"deprecation": {
"replacement": "server.tomcat.max-http-form-post-size",
"level": "error"
}
},
{
"name": "server.use-forward-headers",
"type": "java.lang.Boolean",
"deprecation": {
"reason": "Replaced to support additional strategies.",
"replacement": "server.forward-headers-strategy",
"level": "error"
}
},
{
"name": "spring.aop.auto",
"type": "java.lang.Boolean",

View File

@ -105,12 +105,6 @@ class ServerPropertiesTests {
assertThat(this.properties.getServerHeader()).isEqualTo("Custom Server");
}
@Test
void testConnectionTimeout() {
bind("server.connection-timeout", "60s");
assertThat(this.properties.getConnectionTimeout()).hasMillis(60000);
}
@Test
void testTomcatBinding() {
Map<String, String> map = new HashMap<>();
@ -403,7 +397,7 @@ class ServerPropertiesTests {
@Test
void tomcatMaxHttpPostSizeMatchesConnectorDefault() throws Exception {
assertThat(this.properties.getTomcat().getMaxHttpPostSize().toBytes())
assertThat(this.properties.getTomcat().getMaxHttpFormPostSize().toBytes())
.isEqualTo(getDefaultConnector().getMaxPostSize());
}

View File

@ -41,6 +41,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties.ForwardHeadersStrategy;
import org.springframework.boot.autoconfigure.web.ServerProperties.Jetty;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
@ -251,7 +252,7 @@ class JettyWebServerFactoryCustomizerTests {
@Test
void setUseForwardHeaders() {
this.serverProperties.setUseForwardHeaders(true);
this.serverProperties.setForwardHeadersStrategy(ForwardHeadersStrategy.NATIVE);
ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class);
this.customizer.customize(factory);
verify(factory).setUseForwardHeaders(true);

View File

@ -30,6 +30,7 @@ import reactor.netty.http.server.HttpServer;
import reactor.netty.tcp.TcpServer;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties.ForwardHeadersStrategy;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
import org.springframework.boot.web.embedded.netty.NettyServerCustomizer;
@ -84,14 +85,6 @@ class NettyWebServerFactoryCustomizerTests {
verify(factory).setUseForwardHeaders(false);
}
@Test
void setUseForwardHeaders() {
this.serverProperties.setUseForwardHeaders(true);
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
this.customizer.customize(factory);
verify(factory).setUseForwardHeaders(true);
}
@Test
void forwardHeadersWhenStrategyIsNativeShouldConfigureValve() {
this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE);
@ -109,30 +102,6 @@ class NettyWebServerFactoryCustomizerTests {
verify(factory).setUseForwardHeaders(false);
}
@Test
void setServerConnectionTimeoutAsZero() {
setupServerConnectionTimeout(Duration.ZERO);
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
this.customizer.customize(factory);
verifyConnectionTimeout(factory, null);
}
@Test
void setServerConnectionTimeoutAsMinusOne() {
setupServerConnectionTimeout(Duration.ofNanos(-1));
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
this.customizer.customize(factory);
verifyConnectionTimeout(factory, 0);
}
@Test
void setServerConnectionTimeout() {
setupServerConnectionTimeout(Duration.ofSeconds(1));
NettyReactiveWebServerFactory factory = mock(NettyReactiveWebServerFactory.class);
this.customizer.customize(factory);
verifyConnectionTimeout(factory, 1000);
}
@Test
void setConnectionTimeout() {
setupConnectionTimeout(Duration.ofSeconds(1));
@ -156,14 +125,8 @@ class NettyWebServerFactoryCustomizerTests {
assertThat(options).containsEntry(ChannelOption.CONNECT_TIMEOUT_MILLIS, expected);
}
private void setupServerConnectionTimeout(Duration connectionTimeout) {
this.serverProperties.setUseForwardHeaders(null);
this.serverProperties.setMaxHttpHeaderSize(null);
this.serverProperties.setConnectionTimeout(connectionTimeout);
}
private void setupConnectionTimeout(Duration connectionTimeout) {
this.serverProperties.setUseForwardHeaders(null);
this.serverProperties.setForwardHeadersStrategy(ForwardHeadersStrategy.NONE);
this.serverProperties.setMaxHttpHeaderSize(null);
this.serverProperties.getNetty().setConnectionTimeout(connectionTimeout);
}

View File

@ -32,6 +32,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties.ForwardHeadersStrategy;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
@ -111,12 +112,6 @@ class TomcatWebServerFactoryCustomizerTests {
assertThat(server.getTomcat().getEngine().getBackgroundProcessorDelay()).isEqualTo(5);
}
@Test
void customDisableMaxHttpPostSize() {
bind("server.tomcat.max-http-post-size=-1");
customizeAndRunServer((server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1));
}
@Test
void customDisableMaxHttpFormPostSize() {
bind("server.tomcat.max-http-form-post-size=-1");
@ -131,13 +126,6 @@ class TomcatWebServerFactoryCustomizerTests {
.isEqualTo(5));
}
@Test
void customMaxHttpPostSize() {
bind("server.tomcat.max-http-post-size=10000");
customizeAndRunServer(
(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
}
@Test
void customMaxHttpFormPostSize() {
bind("server.tomcat.max-http-form-post-size=10000");
@ -289,9 +277,8 @@ class TomcatWebServerFactoryCustomizerTests {
}
@Test
void setUseForwardHeaders() {
// Since 1.3.0 no need to explicitly set header names if use-forward-header=true
this.serverProperties.setUseForwardHeaders(true);
void setUseNativeForwardHeadersStrategy() {
this.serverProperties.setForwardHeadersStrategy(ForwardHeadersStrategy.NATIVE);
testRemoteIpValveConfigured();
}

View File

@ -210,14 +210,6 @@ class UndertowWebServerFactoryCustomizerTests {
verify(factory).setUseForwardHeaders(false);
}
@Test
void setUseForwardHeaders() {
this.serverProperties.setUseForwardHeaders(true);
ConfigurableUndertowWebServerFactory factory = mock(ConfigurableUndertowWebServerFactory.class);
this.customizer.customize(factory);
verify(factory).setUseForwardHeaders(true);
}
@Test
void forwardHeadersWhenStrategyIsNativeShouldConfigureValve() {
this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE);

View File

@ -1,3 +1,3 @@
server.compression.enabled: true
server.compression.min-response-size: 1
server.connection-timeout=5000
server.tomcat.connection-timeout=5s