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:
		
							parent
							
								
									7ab2bca376
								
							
						
					
					
						commit
						5afe4743cb
					
				| 
						 | 
					@ -100,13 +100,6 @@ public class ServerProperties {
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	private DataSize maxHttpHeaderSize = DataSize.ofKilobytes(8);
 | 
						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
 | 
						@NestedConfigurationProperty
 | 
				
			||||||
	private Ssl ssl;
 | 
						private Ssl ssl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -145,17 +138,6 @@ public class ServerProperties {
 | 
				
			||||||
		this.address = address;
 | 
							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() {
 | 
						public String getServerHeader() {
 | 
				
			||||||
		return this.serverHeader;
 | 
							return this.serverHeader;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -172,18 +154,6 @@ public class ServerProperties {
 | 
				
			||||||
		this.maxHttpHeaderSize = maxHttpHeaderSize;
 | 
							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() {
 | 
						public ErrorProperties getError() {
 | 
				
			||||||
		return this.error;
 | 
							return this.error;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -443,17 +413,6 @@ public class ServerProperties {
 | 
				
			||||||
			this.getThreads().setMinSpare(minSpareThreads);
 | 
								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() {
 | 
							public DataSize getMaxHttpFormPostSize() {
 | 
				
			||||||
			return this.maxHttpFormPostSize;
 | 
								return this.maxHttpFormPostSize;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -1084,17 +1043,6 @@ public class ServerProperties {
 | 
				
			||||||
			return this.threads;
 | 
								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() {
 | 
							public DataSize getMaxHttpFormPostSize() {
 | 
				
			||||||
			return this.maxHttpFormPostSize;
 | 
								return this.maxHttpFormPostSize;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -87,8 +87,6 @@ public class JettyWebServerFactoryCustomizer
 | 
				
			||||||
						.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
 | 
											.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
 | 
				
			||||||
		propertyMapper.from(jettyProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when(this::isPositive)
 | 
							propertyMapper.from(jettyProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when(this::isPositive)
 | 
				
			||||||
				.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
 | 
									.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
 | 
				
			||||||
		propertyMapper.from(properties::getConnectionTimeout).whenNonNull()
 | 
					 | 
				
			||||||
				.to((connectionTimeout) -> customizeIdleTimeout(factory, connectionTimeout));
 | 
					 | 
				
			||||||
		propertyMapper.from(jettyProperties::getConnectionIdleTimeout).whenNonNull()
 | 
							propertyMapper.from(jettyProperties::getConnectionIdleTimeout).whenNonNull()
 | 
				
			||||||
				.to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
 | 
									.to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout));
 | 
				
			||||||
		propertyMapper.from(jettyProperties::getAccesslog).when(ServerProperties.Jetty.Accesslog::isEnabled)
 | 
							propertyMapper.from(jettyProperties::getAccesslog).when(ServerProperties.Jetty.Accesslog::isEnabled)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -60,8 +60,6 @@ public class NettyWebServerFactoryCustomizer
 | 
				
			||||||
		PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
 | 
							PropertyMapper propertyMapper = PropertyMapper.get().alwaysApplyingWhenNonNull();
 | 
				
			||||||
		propertyMapper.from(this.serverProperties::getMaxHttpHeaderSize)
 | 
							propertyMapper.from(this.serverProperties::getMaxHttpHeaderSize)
 | 
				
			||||||
				.to((maxHttpRequestHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpRequestHeaderSize));
 | 
									.to((maxHttpRequestHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpRequestHeaderSize));
 | 
				
			||||||
		propertyMapper.from(this.serverProperties::getConnectionTimeout)
 | 
					 | 
				
			||||||
				.to((connectionTimeout) -> customizeGenericConnectionTimeout(factory, connectionTimeout));
 | 
					 | 
				
			||||||
		ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
 | 
							ServerProperties.Netty nettyProperties = this.serverProperties.getNetty();
 | 
				
			||||||
		propertyMapper.from(nettyProperties::getConnectionTimeout).whenNonNull()
 | 
							propertyMapper.from(nettyProperties::getConnectionTimeout).whenNonNull()
 | 
				
			||||||
				.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
 | 
									.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
 | 
				
			||||||
| 
						 | 
					@ -80,14 +78,6 @@ public class NettyWebServerFactoryCustomizer
 | 
				
			||||||
				(httpRequestDecoderSpec) -> httpRequestDecoderSpec.maxHeaderSize((int) maxHttpHeaderSize.toBytes())));
 | 
									(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) {
 | 
						private void customizeConnectionTimeout(NettyReactiveWebServerFactory factory, Duration connectionTimeout) {
 | 
				
			||||||
		factory.addServerCustomizers((httpServer) -> httpServer.tcpConfiguration((tcpServer) -> tcpServer
 | 
							factory.addServerCustomizers((httpServer) -> httpServer.tcpConfiguration((tcpServer) -> tcpServer
 | 
				
			||||||
				.selectorOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) connectionTimeout.toMillis())));
 | 
									.selectorOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) connectionTimeout.toMillis())));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -100,8 +100,6 @@ public class TomcatWebServerFactoryCustomizer
 | 
				
			||||||
		propertyMapper.from(tomcatProperties::getAccesslog).when(ServerProperties.Tomcat.Accesslog::isEnabled)
 | 
							propertyMapper.from(tomcatProperties::getAccesslog).when(ServerProperties.Tomcat.Accesslog::isEnabled)
 | 
				
			||||||
				.to((enabled) -> customizeAccessLog(factory));
 | 
									.to((enabled) -> customizeAccessLog(factory));
 | 
				
			||||||
		propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding);
 | 
							propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding);
 | 
				
			||||||
		propertyMapper.from(properties::getConnectionTimeout).whenNonNull()
 | 
					 | 
				
			||||||
				.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
 | 
					 | 
				
			||||||
		propertyMapper.from(tomcatProperties::getConnectionTimeout).whenNonNull()
 | 
							propertyMapper.from(tomcatProperties::getConnectionTimeout).whenNonNull()
 | 
				
			||||||
				.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
 | 
									.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout));
 | 
				
			||||||
		propertyMapper.from(tomcatProperties::getMaxConnections).when(this::isPositive)
 | 
							propertyMapper.from(tomcatProperties::getMaxConnections).when(this::isPositive)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -78,8 +78,6 @@ public class UndertowWebServerFactoryCustomizer
 | 
				
			||||||
		ServerProperties properties = this.serverProperties;
 | 
							ServerProperties properties = this.serverProperties;
 | 
				
			||||||
		map.from(properties::getMaxHttpHeaderSize).asInt(DataSize::toBytes).when(this::isPositive)
 | 
							map.from(properties::getMaxHttpHeaderSize).asInt(DataSize::toBytes).when(this::isPositive)
 | 
				
			||||||
				.to(options.server(UndertowOptions.MAX_HEADER_SIZE));
 | 
									.to(options.server(UndertowOptions.MAX_HEADER_SIZE));
 | 
				
			||||||
		map.from(properties::getConnectionTimeout).asInt(Duration::toMillis)
 | 
					 | 
				
			||||||
				.to(options.server(UndertowOptions.NO_REQUEST_TIMEOUT));
 | 
					 | 
				
			||||||
		mapUndertowProperties(factory, options);
 | 
							mapUndertowProperties(factory, options);
 | 
				
			||||||
		mapAccessLogProperties(factory);
 | 
							mapAccessLogProperties(factory);
 | 
				
			||||||
		map.from(this::getOrDeduceUseForwardHeaders).to(factory::setUseForwardHeaders);
 | 
							map.from(this::getOrDeduceUseForwardHeaders).to(factory::setUseForwardHeaders);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,6 +29,14 @@
 | 
				
			||||||
        "level": "error"
 | 
					        "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",
 | 
					      "name": "server.jetty.accesslog.date-format",
 | 
				
			||||||
      "deprecation": {
 | 
					      "deprecation": {
 | 
				
			||||||
| 
						 | 
					@ -119,6 +127,14 @@
 | 
				
			||||||
      "description": "Whether to enable HTTP/2 support, if the current environment supports it.",
 | 
					      "description": "Whether to enable HTTP/2 support, if the current environment supports it.",
 | 
				
			||||||
      "defaultValue": false
 | 
					      "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",
 | 
					      "name": "server.port",
 | 
				
			||||||
      "defaultValue": 8080
 | 
					      "defaultValue": 8080
 | 
				
			||||||
| 
						 | 
					@ -245,6 +261,23 @@
 | 
				
			||||||
      "name": "server.ssl.trust-store-type",
 | 
					      "name": "server.ssl.trust-store-type",
 | 
				
			||||||
      "description": "Type of the trust store."
 | 
					      "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",
 | 
					      "name": "spring.aop.auto",
 | 
				
			||||||
      "type": "java.lang.Boolean",
 | 
					      "type": "java.lang.Boolean",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -105,12 +105,6 @@ class ServerPropertiesTests {
 | 
				
			||||||
		assertThat(this.properties.getServerHeader()).isEqualTo("Custom Server");
 | 
							assertThat(this.properties.getServerHeader()).isEqualTo("Custom Server");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
					 | 
				
			||||||
	void testConnectionTimeout() {
 | 
					 | 
				
			||||||
		bind("server.connection-timeout", "60s");
 | 
					 | 
				
			||||||
		assertThat(this.properties.getConnectionTimeout()).hasMillis(60000);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	void testTomcatBinding() {
 | 
						void testTomcatBinding() {
 | 
				
			||||||
		Map<String, String> map = new HashMap<>();
 | 
							Map<String, String> map = new HashMap<>();
 | 
				
			||||||
| 
						 | 
					@ -403,7 +397,7 @@ class ServerPropertiesTests {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	void tomcatMaxHttpPostSizeMatchesConnectorDefault() throws Exception {
 | 
						void tomcatMaxHttpPostSizeMatchesConnectorDefault() throws Exception {
 | 
				
			||||||
		assertThat(this.properties.getTomcat().getMaxHttpPostSize().toBytes())
 | 
							assertThat(this.properties.getTomcat().getMaxHttpFormPostSize().toBytes())
 | 
				
			||||||
				.isEqualTo(getDefaultConnector().getMaxPostSize());
 | 
									.isEqualTo(getDefaultConnector().getMaxPostSize());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,6 +41,7 @@ import org.junit.jupiter.api.BeforeEach;
 | 
				
			||||||
import org.junit.jupiter.api.Test;
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
 | 
					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.autoconfigure.web.ServerProperties.Jetty;
 | 
				
			||||||
import org.springframework.boot.context.properties.bind.Bindable;
 | 
					import org.springframework.boot.context.properties.bind.Bindable;
 | 
				
			||||||
import org.springframework.boot.context.properties.bind.Binder;
 | 
					import org.springframework.boot.context.properties.bind.Binder;
 | 
				
			||||||
| 
						 | 
					@ -251,7 +252,7 @@ class JettyWebServerFactoryCustomizerTests {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	void setUseForwardHeaders() {
 | 
						void setUseForwardHeaders() {
 | 
				
			||||||
		this.serverProperties.setUseForwardHeaders(true);
 | 
							this.serverProperties.setForwardHeadersStrategy(ForwardHeadersStrategy.NATIVE);
 | 
				
			||||||
		ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class);
 | 
							ConfigurableJettyWebServerFactory factory = mock(ConfigurableJettyWebServerFactory.class);
 | 
				
			||||||
		this.customizer.customize(factory);
 | 
							this.customizer.customize(factory);
 | 
				
			||||||
		verify(factory).setUseForwardHeaders(true);
 | 
							verify(factory).setUseForwardHeaders(true);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -30,6 +30,7 @@ import reactor.netty.http.server.HttpServer;
 | 
				
			||||||
import reactor.netty.tcp.TcpServer;
 | 
					import reactor.netty.tcp.TcpServer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
 | 
					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.context.properties.source.ConfigurationPropertySources;
 | 
				
			||||||
import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
 | 
					import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory;
 | 
				
			||||||
import org.springframework.boot.web.embedded.netty.NettyServerCustomizer;
 | 
					import org.springframework.boot.web.embedded.netty.NettyServerCustomizer;
 | 
				
			||||||
| 
						 | 
					@ -84,14 +85,6 @@ class NettyWebServerFactoryCustomizerTests {
 | 
				
			||||||
		verify(factory).setUseForwardHeaders(false);
 | 
							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
 | 
						@Test
 | 
				
			||||||
	void forwardHeadersWhenStrategyIsNativeShouldConfigureValve() {
 | 
						void forwardHeadersWhenStrategyIsNativeShouldConfigureValve() {
 | 
				
			||||||
		this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE);
 | 
							this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE);
 | 
				
			||||||
| 
						 | 
					@ -109,30 +102,6 @@ class NettyWebServerFactoryCustomizerTests {
 | 
				
			||||||
		verify(factory).setUseForwardHeaders(false);
 | 
							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
 | 
						@Test
 | 
				
			||||||
	void setConnectionTimeout() {
 | 
						void setConnectionTimeout() {
 | 
				
			||||||
		setupConnectionTimeout(Duration.ofSeconds(1));
 | 
							setupConnectionTimeout(Duration.ofSeconds(1));
 | 
				
			||||||
| 
						 | 
					@ -156,14 +125,8 @@ class NettyWebServerFactoryCustomizerTests {
 | 
				
			||||||
		assertThat(options).containsEntry(ChannelOption.CONNECT_TIMEOUT_MILLIS, expected);
 | 
							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) {
 | 
						private void setupConnectionTimeout(Duration connectionTimeout) {
 | 
				
			||||||
		this.serverProperties.setUseForwardHeaders(null);
 | 
							this.serverProperties.setForwardHeadersStrategy(ForwardHeadersStrategy.NONE);
 | 
				
			||||||
		this.serverProperties.setMaxHttpHeaderSize(null);
 | 
							this.serverProperties.setMaxHttpHeaderSize(null);
 | 
				
			||||||
		this.serverProperties.getNetty().setConnectionTimeout(connectionTimeout);
 | 
							this.serverProperties.getNetty().setConnectionTimeout(connectionTimeout);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,6 +32,7 @@ import org.junit.jupiter.api.BeforeEach;
 | 
				
			||||||
import org.junit.jupiter.api.Test;
 | 
					import org.junit.jupiter.api.Test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
 | 
					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.Bindable;
 | 
				
			||||||
import org.springframework.boot.context.properties.bind.Binder;
 | 
					import org.springframework.boot.context.properties.bind.Binder;
 | 
				
			||||||
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
 | 
					import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
 | 
				
			||||||
| 
						 | 
					@ -111,12 +112,6 @@ class TomcatWebServerFactoryCustomizerTests {
 | 
				
			||||||
		assertThat(server.getTomcat().getEngine().getBackgroundProcessorDelay()).isEqualTo(5);
 | 
							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
 | 
						@Test
 | 
				
			||||||
	void customDisableMaxHttpFormPostSize() {
 | 
						void customDisableMaxHttpFormPostSize() {
 | 
				
			||||||
		bind("server.tomcat.max-http-form-post-size=-1");
 | 
							bind("server.tomcat.max-http-form-post-size=-1");
 | 
				
			||||||
| 
						 | 
					@ -131,13 +126,6 @@ class TomcatWebServerFactoryCustomizerTests {
 | 
				
			||||||
						.isEqualTo(5));
 | 
											.isEqualTo(5));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
					 | 
				
			||||||
	void customMaxHttpPostSize() {
 | 
					 | 
				
			||||||
		bind("server.tomcat.max-http-post-size=10000");
 | 
					 | 
				
			||||||
		customizeAndRunServer(
 | 
					 | 
				
			||||||
				(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	void customMaxHttpFormPostSize() {
 | 
						void customMaxHttpFormPostSize() {
 | 
				
			||||||
		bind("server.tomcat.max-http-form-post-size=10000");
 | 
							bind("server.tomcat.max-http-form-post-size=10000");
 | 
				
			||||||
| 
						 | 
					@ -289,9 +277,8 @@ class TomcatWebServerFactoryCustomizerTests {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	void setUseForwardHeaders() {
 | 
						void setUseNativeForwardHeadersStrategy() {
 | 
				
			||||||
		// Since 1.3.0 no need to explicitly set header names if use-forward-header=true
 | 
							this.serverProperties.setForwardHeadersStrategy(ForwardHeadersStrategy.NATIVE);
 | 
				
			||||||
		this.serverProperties.setUseForwardHeaders(true);
 | 
					 | 
				
			||||||
		testRemoteIpValveConfigured();
 | 
							testRemoteIpValveConfigured();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -210,14 +210,6 @@ class UndertowWebServerFactoryCustomizerTests {
 | 
				
			||||||
		verify(factory).setUseForwardHeaders(false);
 | 
							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
 | 
						@Test
 | 
				
			||||||
	void forwardHeadersWhenStrategyIsNativeShouldConfigureValve() {
 | 
						void forwardHeadersWhenStrategyIsNativeShouldConfigureValve() {
 | 
				
			||||||
		this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE);
 | 
							this.serverProperties.setForwardHeadersStrategy(ServerProperties.ForwardHeadersStrategy.NATIVE);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,3 +1,3 @@
 | 
				
			||||||
server.compression.enabled: true
 | 
					server.compression.enabled: true
 | 
				
			||||||
server.compression.min-response-size: 1
 | 
					server.compression.min-response-size: 1
 | 
				
			||||||
server.connection-timeout=5000
 | 
					server.tomcat.connection-timeout=5s
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue