Rename `max-http-post-size` server property
Rename `max-http-post-size` to `max-http-form-post-size` for Jetty and Tomcat to make it clearer that they only apply to POSTed form content. See gh-18566
This commit is contained in:
parent
63f60fc5d9
commit
81dc6e02e6
|
|
@ -56,6 +56,7 @@ import org.springframework.util.unit.DataSize;
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
* @author Chentao Qu
|
* @author Chentao Qu
|
||||||
|
* @author Rafiullah Hamedy
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
|
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
|
||||||
|
|
@ -334,16 +335,16 @@ public class ServerProperties {
|
||||||
*/
|
*/
|
||||||
private int minSpareThreads = 10;
|
private int minSpareThreads = 10;
|
||||||
|
|
||||||
/**
|
|
||||||
* Maximum size of the HTTP post content.
|
|
||||||
*/
|
|
||||||
private DataSize maxHttpPostSize = DataSize.ofMegabytes(2);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum size of the HTTP message header.
|
* Maximum size of the HTTP message header.
|
||||||
*/
|
*/
|
||||||
private DataSize maxHttpHeaderSize = DataSize.ofBytes(0);
|
private DataSize maxHttpHeaderSize = DataSize.ofBytes(0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum size of the form content in any HTTP post request.
|
||||||
|
*/
|
||||||
|
private DataSize maxHttpFormPostSize = DataSize.ofMegabytes(2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum amount of request body to swallow.
|
* Maximum amount of request body to swallow.
|
||||||
*/
|
*/
|
||||||
|
|
@ -413,12 +414,23 @@ public class ServerProperties {
|
||||||
this.minSpareThreads = minSpareThreads;
|
this.minSpareThreads = minSpareThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@DeprecatedConfigurationProperty(replacement = "server.tomcat.max-http-form-post-size")
|
||||||
public DataSize getMaxHttpPostSize() {
|
public DataSize getMaxHttpPostSize() {
|
||||||
return this.maxHttpPostSize;
|
return this.maxHttpFormPostSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
|
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() {
|
public Accesslog getAccesslog() {
|
||||||
|
|
@ -746,9 +758,9 @@ public class ServerProperties {
|
||||||
private final Accesslog accesslog = new Accesslog();
|
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
|
* Number of acceptor threads to use. When the value is -1, the default, the
|
||||||
|
|
@ -771,12 +783,23 @@ public class ServerProperties {
|
||||||
return this.accesslog;
|
return this.accesslog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@DeprecatedConfigurationProperty(replacement = "server.jetty.max-http-form-post-size")
|
||||||
public DataSize getMaxHttpPostSize() {
|
public DataSize getMaxHttpPostSize() {
|
||||||
return this.maxHttpPostSize;
|
return this.maxHttpFormPostSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
|
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() {
|
public Integer getAcceptors() {
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ import org.springframework.util.unit.DataSize;
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Rafiullah Hamedy
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public class JettyWebServerFactoryCustomizer
|
public class JettyWebServerFactoryCustomizer
|
||||||
|
|
@ -74,8 +75,8 @@ public class JettyWebServerFactoryCustomizer
|
||||||
propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull().asInt(DataSize::toBytes)
|
propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull().asInt(DataSize::toBytes)
|
||||||
.when(this::isPositive).to((maxHttpHeaderSize) -> factory
|
.when(this::isPositive).to((maxHttpHeaderSize) -> factory
|
||||||
.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
|
.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
|
||||||
propertyMapper.from(jettyProperties::getMaxHttpPostSize).asInt(DataSize::toBytes).when(this::isPositive)
|
propertyMapper.from(jettyProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when(this::isPositive)
|
||||||
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
|
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
|
||||||
propertyMapper.from(properties::getConnectionTimeout).whenNonNull()
|
propertyMapper.from(properties::getConnectionTimeout).whenNonNull()
|
||||||
.to((connectionTimeout) -> customizeIdleTimeout(factory, connectionTimeout));
|
.to((connectionTimeout) -> customizeIdleTimeout(factory, connectionTimeout));
|
||||||
propertyMapper.from(jettyProperties::getConnectionIdleTimeout).whenNonNull()
|
propertyMapper.from(jettyProperties::getConnectionIdleTimeout).whenNonNull()
|
||||||
|
|
@ -106,24 +107,24 @@ public class JettyWebServerFactoryCustomizer
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void customizeMaxHttpPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpPostSize) {
|
private void customizeMaxHttpFormPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpFormPostSize) {
|
||||||
factory.addServerCustomizers(new JettyServerCustomizer() {
|
factory.addServerCustomizers(new JettyServerCustomizer() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void customize(Server server) {
|
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) {
|
for (Handler handler : handlers) {
|
||||||
if (handler instanceof ContextHandler) {
|
if (handler instanceof ContextHandler) {
|
||||||
((ContextHandler) handler).setMaxFormContentSize(maxHttpPostSize);
|
((ContextHandler) handler).setMaxFormContentSize(maxHttpFormPostSize);
|
||||||
}
|
}
|
||||||
else if (handler instanceof HandlerWrapper) {
|
else if (handler instanceof HandlerWrapper) {
|
||||||
setHandlerMaxHttpPostSize(maxHttpPostSize, ((HandlerWrapper) handler).getHandler());
|
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, ((HandlerWrapper) handler).getHandler());
|
||||||
}
|
}
|
||||||
else if (handler instanceof HandlerCollection) {
|
else if (handler instanceof HandlerCollection) {
|
||||||
setHandlerMaxHttpPostSize(maxHttpPostSize, ((HandlerCollection) handler).getHandlers());
|
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, ((HandlerCollection) handler).getHandlers());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ import org.springframework.util.unit.DataSize;
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
* @author Artsiom Yudovin
|
* @author Artsiom Yudovin
|
||||||
* @author Chentao Qu
|
* @author Chentao Qu
|
||||||
|
* @author Rafiullah Hamedy
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public class TomcatWebServerFactoryCustomizer
|
public class TomcatWebServerFactoryCustomizer
|
||||||
|
|
@ -86,9 +87,9 @@ public class TomcatWebServerFactoryCustomizer
|
||||||
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize));
|
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize));
|
||||||
propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull().asInt(DataSize::toBytes)
|
propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull().asInt(DataSize::toBytes)
|
||||||
.to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
|
.to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
|
||||||
propertyMapper.from(tomcatProperties::getMaxHttpPostSize).asInt(DataSize::toBytes)
|
propertyMapper.from(tomcatProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes)
|
||||||
.when((maxHttpPostSize) -> maxHttpPostSize != 0)
|
.when((maxHttpFormPostSize) -> maxHttpFormPostSize != 0)
|
||||||
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
|
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
|
||||||
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);
|
||||||
|
|
@ -218,8 +219,8 @@ public class TomcatWebServerFactoryCustomizer
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void customizeMaxHttpPostSize(ConfigurableTomcatWebServerFactory factory, int maxHttpPostSize) {
|
private void customizeMaxHttpFormPostSize(ConfigurableTomcatWebServerFactory factory, int maxHttpFormPostSize) {
|
||||||
factory.addConnectorCustomizers((connector) -> connector.setMaxPostSize(maxHttpPostSize));
|
factory.addConnectorCustomizers((connector) -> connector.setMaxPostSize(maxHttpFormPostSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void customizeAccessLog(ConfigurableTomcatWebServerFactory factory) {
|
private void customizeAccessLog(ConfigurableTomcatWebServerFactory factory) {
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Eddú Meléndez
|
* @author Eddú Meléndez
|
||||||
* @author Quinten De Swaef
|
* @author Quinten De Swaef
|
||||||
* @author Venil Noronha
|
* @author Venil Noronha
|
||||||
|
* @author Rafiullah Hamedy
|
||||||
*/
|
*/
|
||||||
public class ServerPropertiesTests {
|
public class ServerPropertiesTests {
|
||||||
|
|
||||||
|
|
@ -219,6 +220,12 @@ public class ServerPropertiesTests {
|
||||||
.isEqualTo(getDefaultConnector().getMaxPostSize());
|
.isEqualTo(getDefaultConnector().getMaxPostSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void tomcatMaxHttpFormPostSizeMatchesConnectorDefault() throws Exception {
|
||||||
|
assertThat(this.properties.getTomcat().getMaxHttpFormPostSize().toBytes())
|
||||||
|
.isEqualTo(getDefaultConnector().getMaxPostSize());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void tomcatBackgroundProcessorDelayMatchesEngineDefault() {
|
public void tomcatBackgroundProcessorDelayMatchesEngineDefault() {
|
||||||
assertThat(this.properties.getTomcat().getBackgroundProcessorDelay())
|
assertThat(this.properties.getTomcat().getBackgroundProcessorDelay())
|
||||||
|
|
@ -256,7 +263,7 @@ public class ServerPropertiesTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jettyMaxHttpPostSizeMatchesDefault() throws Exception {
|
public void jettyMaxHttpFormPostSizeMatchesDefault() throws Exception {
|
||||||
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);
|
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);
|
||||||
JettyWebServer jetty = (JettyWebServer) jettyFactory
|
JettyWebServer jetty = (JettyWebServer) jettyFactory
|
||||||
.getWebServer((ServletContextInitializer) (servletContext) -> servletContext
|
.getWebServer((ServletContextInitializer) (servletContext) -> servletContext
|
||||||
|
|
@ -308,7 +315,7 @@ public class ServerPropertiesTests {
|
||||||
assertThat(failure.get()).isNotNull();
|
assertThat(failure.get()).isNotNull();
|
||||||
String message = failure.get().getCause().getMessage();
|
String message = failure.get().getCause().getMessage();
|
||||||
int defaultMaxPostSize = Integer.valueOf(message.substring(message.lastIndexOf(' ')).trim());
|
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 {
|
finally {
|
||||||
jetty.stop();
|
jetty.stop();
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Rob Tompkins
|
* @author Rob Tompkins
|
||||||
* @author Artsiom Yudovin
|
* @author Artsiom Yudovin
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
|
* @author Rafiullah Hamedy
|
||||||
*/
|
*/
|
||||||
public class TomcatWebServerFactoryCustomizerTests {
|
public class TomcatWebServerFactoryCustomizerTests {
|
||||||
|
|
||||||
|
|
@ -95,6 +96,12 @@ public class TomcatWebServerFactoryCustomizerTests {
|
||||||
customizeAndRunServer((server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1));
|
customizeAndRunServer((server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void customDisableMaxHttpFormPostSize() {
|
||||||
|
bind("server.tomcat.max-http-form-post-size=-1");
|
||||||
|
customizeAndRunServer((server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customMaxConnections() {
|
public void customMaxConnections() {
|
||||||
bind("server.tomcat.max-connections=5");
|
bind("server.tomcat.max-connections=5");
|
||||||
|
|
@ -110,6 +117,13 @@ public class TomcatWebServerFactoryCustomizerTests {
|
||||||
(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
|
(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void customMaxHttpFormPostSize() {
|
||||||
|
bind("server.tomcat.max-http-form-post-size=10000");
|
||||||
|
customizeAndRunServer(
|
||||||
|
(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customMaxHttpHeaderSize() {
|
public void customMaxHttpHeaderSize() {
|
||||||
bind("server.max-http-header-size=1KB");
|
bind("server.max-http-header-size=1KB");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue