Merge branch '2.1.x'
Closes gh-18695
This commit is contained in:
@@ -359,9 +359,9 @@ public class ServerProperties {
|
||||
private int minSpareThreads = 10;
|
||||
|
||||
/**
|
||||
* Maximum size of the HTTP post content.
|
||||
* Maximum size of the form content in any HTTP post request.
|
||||
*/
|
||||
private DataSize maxHttpPostSize = DataSize.ofMegabytes(2);
|
||||
private DataSize maxHttpFormPostSize = DataSize.ofMegabytes(2);
|
||||
|
||||
/**
|
||||
* Maximum amount of request body to swallow.
|
||||
@@ -456,12 +456,23 @@ public class ServerProperties {
|
||||
this.minSpareThreads = minSpareThreads;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@DeprecatedConfigurationProperty(replacement = "server.tomcat.max-http-form-post-size")
|
||||
public DataSize getMaxHttpPostSize() {
|
||||
return this.maxHttpPostSize;
|
||||
return this.maxHttpFormPostSize;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
|
||||
this.maxHttpPostSize = maxHttpPostSize;
|
||||
this.maxHttpFormPostSize = maxHttpPostSize;
|
||||
}
|
||||
|
||||
public DataSize getMaxHttpFormPostSize() {
|
||||
return this.maxHttpFormPostSize;
|
||||
}
|
||||
|
||||
public void setMaxHttpFormPostSize(DataSize maxHttpFormPostSize) {
|
||||
this.maxHttpFormPostSize = maxHttpFormPostSize;
|
||||
}
|
||||
|
||||
public Accesslog getAccesslog() {
|
||||
@@ -927,9 +938,9 @@ public class ServerProperties {
|
||||
private final Accesslog accesslog = new Accesslog();
|
||||
|
||||
/**
|
||||
* Maximum size of the HTTP post or put content.
|
||||
* Maximum size of the form content in any HTTP post request.
|
||||
*/
|
||||
private DataSize maxHttpPostSize = DataSize.ofBytes(200000);
|
||||
private DataSize maxHttpFormPostSize = DataSize.ofBytes(200000);
|
||||
|
||||
/**
|
||||
* Number of acceptor threads to use. When the value is -1, the default, the
|
||||
@@ -967,12 +978,23 @@ public class ServerProperties {
|
||||
return this.accesslog;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@DeprecatedConfigurationProperty(replacement = "server.jetty.max-http-form-post-size")
|
||||
public DataSize getMaxHttpPostSize() {
|
||||
return this.maxHttpPostSize;
|
||||
return this.maxHttpFormPostSize;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
|
||||
this.maxHttpPostSize = maxHttpPostSize;
|
||||
this.maxHttpFormPostSize = maxHttpPostSize;
|
||||
}
|
||||
|
||||
public DataSize getMaxHttpFormPostSize() {
|
||||
return this.maxHttpFormPostSize;
|
||||
}
|
||||
|
||||
public void setMaxHttpFormPostSize(DataSize maxHttpFormPostSize) {
|
||||
this.maxHttpFormPostSize = maxHttpFormPostSize;
|
||||
}
|
||||
|
||||
public Integer getAcceptors() {
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.springframework.util.unit.DataSize;
|
||||
* @author Brian Clozel
|
||||
* @author Phillip Webb
|
||||
* @author HaiTao Zhang
|
||||
* @author Rafiullah Hamedy
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class JettyWebServerFactoryCustomizer
|
||||
@@ -80,8 +81,8 @@ public class JettyWebServerFactoryCustomizer
|
||||
propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull().asInt(DataSize::toBytes)
|
||||
.when(this::isPositive).to((maxHttpHeaderSize) -> factory
|
||||
.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
|
||||
propertyMapper.from(jettyProperties::getMaxHttpPostSize).asInt(DataSize::toBytes).when(this::isPositive)
|
||||
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
|
||||
propertyMapper.from(jettyProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when(this::isPositive)
|
||||
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
|
||||
propertyMapper.from(jettyProperties::getMaxThreads).when(this::isPositive)
|
||||
.to((maxThreads) -> customizeThreadPool(factory, (threadPool) -> threadPool.setMaxThreads(maxThreads)));
|
||||
propertyMapper.from(jettyProperties::getMinThreads).when(this::isPositive)
|
||||
@@ -118,24 +119,24 @@ public class JettyWebServerFactoryCustomizer
|
||||
});
|
||||
}
|
||||
|
||||
private void customizeMaxHttpPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpPostSize) {
|
||||
private void customizeMaxHttpFormPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpFormPostSize) {
|
||||
factory.addServerCustomizers(new JettyServerCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(Server server) {
|
||||
setHandlerMaxHttpPostSize(maxHttpPostSize, server.getHandlers());
|
||||
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, server.getHandlers());
|
||||
}
|
||||
|
||||
private void setHandlerMaxHttpPostSize(int maxHttpPostSize, Handler... handlers) {
|
||||
private void setHandlerMaxHttpFormPostSize(int maxHttpPostSize, Handler... handlers) {
|
||||
for (Handler handler : handlers) {
|
||||
if (handler instanceof ContextHandler) {
|
||||
((ContextHandler) handler).setMaxFormContentSize(maxHttpPostSize);
|
||||
((ContextHandler) handler).setMaxFormContentSize(maxHttpFormPostSize);
|
||||
}
|
||||
else if (handler instanceof HandlerWrapper) {
|
||||
setHandlerMaxHttpPostSize(maxHttpPostSize, ((HandlerWrapper) handler).getHandler());
|
||||
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, ((HandlerWrapper) handler).getHandler());
|
||||
}
|
||||
else if (handler instanceof HandlerCollection) {
|
||||
setHandlerMaxHttpPostSize(maxHttpPostSize, ((HandlerCollection) handler).getHandlers());
|
||||
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, ((HandlerCollection) handler).getHandlers());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ import org.springframework.util.unit.DataSize;
|
||||
* @author Chentao Qu
|
||||
* @author Andrew McGhie
|
||||
* @author Dirk Deyne
|
||||
* @author Rafiullah Hamedy
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public class TomcatWebServerFactoryCustomizer
|
||||
@@ -91,9 +92,9 @@ public class TomcatWebServerFactoryCustomizer
|
||||
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize));
|
||||
propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull().asInt(DataSize::toBytes)
|
||||
.to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
|
||||
propertyMapper.from(tomcatProperties::getMaxHttpPostSize).asInt(DataSize::toBytes)
|
||||
.when((maxHttpPostSize) -> maxHttpPostSize != 0)
|
||||
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
|
||||
propertyMapper.from(tomcatProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes)
|
||||
.when((maxHttpFormPostSize) -> maxHttpFormPostSize != 0)
|
||||
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
|
||||
propertyMapper.from(tomcatProperties::getAccesslog).when(ServerProperties.Tomcat.Accesslog::isEnabled)
|
||||
.to((enabled) -> customizeAccessLog(factory));
|
||||
propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding);
|
||||
@@ -244,8 +245,8 @@ public class TomcatWebServerFactoryCustomizer
|
||||
});
|
||||
}
|
||||
|
||||
private void customizeMaxHttpPostSize(ConfigurableTomcatWebServerFactory factory, int maxHttpPostSize) {
|
||||
factory.addConnectorCustomizers((connector) -> connector.setMaxPostSize(maxHttpPostSize));
|
||||
private void customizeMaxHttpFormPostSize(ConfigurableTomcatWebServerFactory factory, int maxHttpFormPostSize) {
|
||||
factory.addConnectorCustomizers((connector) -> connector.setMaxPostSize(maxHttpFormPostSize));
|
||||
}
|
||||
|
||||
private void customizeAccessLog(ConfigurableTomcatWebServerFactory factory) {
|
||||
|
||||
@@ -75,6 +75,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Venil Noronha
|
||||
* @author Andrew McGhie
|
||||
* @author HaiTao Zhang
|
||||
* @author Rafiullah Hamedy
|
||||
*/
|
||||
class ServerPropertiesTests {
|
||||
|
||||
@@ -310,6 +311,12 @@ class ServerPropertiesTests {
|
||||
.isEqualTo(Duration.ofSeconds((new StandardEngine().getBackgroundProcessorDelay())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tomcatMaxHttpFormPostSizeMatchesConnectorDefault() throws Exception {
|
||||
assertThat(this.properties.getTomcat().getMaxHttpFormPostSize().toBytes())
|
||||
.isEqualTo(getDefaultConnector().getMaxPostSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tomcatUriEncodingMatchesConnectorDefault() throws Exception {
|
||||
assertThat(this.properties.getTomcat().getUriEncoding().name())
|
||||
@@ -341,7 +348,7 @@ class ServerPropertiesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void jettyMaxHttpPostSizeMatchesDefault() throws Exception {
|
||||
void jettyMaxHttpFormPostSizeMatchesDefault() throws Exception {
|
||||
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);
|
||||
JettyWebServer jetty = (JettyWebServer) jettyFactory
|
||||
.getWebServer((ServletContextInitializer) (servletContext) -> servletContext
|
||||
@@ -393,7 +400,7 @@ class ServerPropertiesTests {
|
||||
assertThat(failure.get()).isNotNull();
|
||||
String message = failure.get().getCause().getMessage();
|
||||
int defaultMaxPostSize = Integer.valueOf(message.substring(message.lastIndexOf(' ')).trim());
|
||||
assertThat(this.properties.getJetty().getMaxHttpPostSize().toBytes()).isEqualTo(defaultMaxPostSize);
|
||||
assertThat(this.properties.getJetty().getMaxHttpFormPostSize().toBytes()).isEqualTo(defaultMaxPostSize);
|
||||
}
|
||||
finally {
|
||||
jetty.stop();
|
||||
|
||||
@@ -52,6 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Artsiom Yudovin
|
||||
* @author Stephane Nicoll
|
||||
* @author Andrew McGhie
|
||||
* @author Rafiullah Hamedy
|
||||
*/
|
||||
class TomcatWebServerFactoryCustomizerTests {
|
||||
|
||||
@@ -114,6 +115,12 @@ class TomcatWebServerFactoryCustomizerTests {
|
||||
customizeAndRunServer((server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customDisableMaxHttpFormPostSize() {
|
||||
bind("server.tomcat.max-http-form-post-size=-1");
|
||||
customizeAndRunServer((server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customMaxConnections() {
|
||||
bind("server.tomcat.max-connections=5");
|
||||
@@ -129,6 +136,13 @@ class TomcatWebServerFactoryCustomizerTests {
|
||||
(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customMaxHttpFormPostSize() {
|
||||
bind("server.tomcat.max-http-form-post-size=10000");
|
||||
customizeAndRunServer(
|
||||
(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customMaxHttpHeaderSize() {
|
||||
bind("server.max-http-header-size=1KB");
|
||||
|
||||
Reference in New Issue
Block a user