Add dedicated settings for maxHttpPostSize
This commit deprecates `server.max-http-post-size` and introduces a dedicated property for each supported container. In particular, Undertow can now define a max size higher than 2GB. Closes gh-7362
This commit is contained in:
parent
dce1487424
commit
0befc310cd
|
|
@ -362,12 +362,18 @@ public class ServerProperties
|
||||||
this.maxHttpHeaderSize = maxHttpHeaderSize;
|
this.maxHttpHeaderSize = maxHttpHeaderSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
@DeprecatedConfigurationProperty(reason = "Use dedicated property for each container.")
|
||||||
public int getMaxHttpPostSize() {
|
public int getMaxHttpPostSize() {
|
||||||
return this.maxHttpPostSize;
|
return this.maxHttpPostSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public void setMaxHttpPostSize(int maxHttpPostSize) {
|
public void setMaxHttpPostSize(int maxHttpPostSize) {
|
||||||
this.maxHttpPostSize = maxHttpPostSize;
|
this.maxHttpPostSize = maxHttpPostSize;
|
||||||
|
this.jetty.setMaxHttpPostSize(maxHttpPostSize);
|
||||||
|
this.tomcat.setMaxHttpPostSize(maxHttpPostSize);
|
||||||
|
this.undertow.setMaxHttpPostSize(maxHttpPostSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean getOrDeduceUseForwardHeaders() {
|
protected final boolean getOrDeduceUseForwardHeaders() {
|
||||||
|
|
@ -645,6 +651,11 @@ public class ServerProperties
|
||||||
*/
|
*/
|
||||||
private int minSpareThreads = 0; // Minimum spare threads in protocol handler
|
private int minSpareThreads = 0; // Minimum spare threads in protocol handler
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum size in bytes of the HTTP post content.
|
||||||
|
*/
|
||||||
|
private int maxHttpPostSize = 0; // bytes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum size in bytes of the HTTP message header.
|
* Maximum size in bytes of the HTTP message header.
|
||||||
*/
|
*/
|
||||||
|
|
@ -697,6 +708,14 @@ public class ServerProperties
|
||||||
this.minSpareThreads = minSpareThreads;
|
this.minSpareThreads = minSpareThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxHttpPostSize() {
|
||||||
|
return this.maxHttpPostSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxHttpPostSize(int maxHttpPostSize) {
|
||||||
|
this.maxHttpPostSize = maxHttpPostSize;
|
||||||
|
}
|
||||||
|
|
||||||
public Accesslog getAccesslog() {
|
public Accesslog getAccesslog() {
|
||||||
return this.accesslog;
|
return this.accesslog;
|
||||||
}
|
}
|
||||||
|
|
@ -815,8 +834,8 @@ public class ServerProperties
|
||||||
if (maxHttpHeaderSize > 0) {
|
if (maxHttpHeaderSize > 0) {
|
||||||
customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize);
|
customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize);
|
||||||
}
|
}
|
||||||
if (serverProperties.getMaxHttpPostSize() > 0) {
|
if (this.maxHttpPostSize > 0) {
|
||||||
customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize());
|
customizeMaxHttpPostSize(factory, this.maxHttpPostSize);
|
||||||
}
|
}
|
||||||
if (this.accesslog.enabled) {
|
if (this.accesslog.enabled) {
|
||||||
customizeAccessLog(factory);
|
customizeAccessLog(factory);
|
||||||
|
|
@ -1116,6 +1135,11 @@ public class ServerProperties
|
||||||
|
|
||||||
public static class Jetty {
|
public static class Jetty {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum size in bytes of the HTTP post or put content.
|
||||||
|
*/
|
||||||
|
private int maxHttpPostSize = 0; // bytes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of acceptor threads to use.
|
* Number of acceptor threads to use.
|
||||||
*/
|
*/
|
||||||
|
|
@ -1126,6 +1150,14 @@ public class ServerProperties
|
||||||
*/
|
*/
|
||||||
private Integer selectors;
|
private Integer selectors;
|
||||||
|
|
||||||
|
public int getMaxHttpPostSize() {
|
||||||
|
return this.maxHttpPostSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxHttpPostSize(int maxHttpPostSize) {
|
||||||
|
this.maxHttpPostSize = maxHttpPostSize;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getAcceptors() {
|
public Integer getAcceptors() {
|
||||||
return this.acceptors;
|
return this.acceptors;
|
||||||
}
|
}
|
||||||
|
|
@ -1155,8 +1187,8 @@ public class ServerProperties
|
||||||
customizeMaxHttpHeaderSize(factory,
|
customizeMaxHttpHeaderSize(factory,
|
||||||
serverProperties.getMaxHttpHeaderSize());
|
serverProperties.getMaxHttpHeaderSize());
|
||||||
}
|
}
|
||||||
if (serverProperties.getMaxHttpPostSize() > 0) {
|
if (this.maxHttpPostSize > 0) {
|
||||||
customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize());
|
customizeMaxHttpPostSize(factory, this.maxHttpPostSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverProperties.getConnectionTimeout() != null) {
|
if (serverProperties.getConnectionTimeout() != null) {
|
||||||
|
|
@ -1266,6 +1298,11 @@ public class ServerProperties
|
||||||
|
|
||||||
public static class Undertow {
|
public static class Undertow {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum size in bytes of the HTTP post content.
|
||||||
|
*/
|
||||||
|
private long maxHttpPostSize = 0; // bytes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Size of each buffer in bytes.
|
* Size of each buffer in bytes.
|
||||||
*/
|
*/
|
||||||
|
|
@ -1294,6 +1331,14 @@ public class ServerProperties
|
||||||
|
|
||||||
private final Accesslog accesslog = new Accesslog();
|
private final Accesslog accesslog = new Accesslog();
|
||||||
|
|
||||||
|
public long getMaxHttpPostSize() {
|
||||||
|
return this.maxHttpPostSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaxHttpPostSize(long maxHttpPostSize) {
|
||||||
|
this.maxHttpPostSize = maxHttpPostSize;
|
||||||
|
}
|
||||||
|
|
||||||
public Integer getBufferSize() {
|
public Integer getBufferSize() {
|
||||||
return this.bufferSize;
|
return this.bufferSize;
|
||||||
}
|
}
|
||||||
|
|
@ -1366,8 +1411,8 @@ public class ServerProperties
|
||||||
customizeMaxHttpHeaderSize(factory,
|
customizeMaxHttpHeaderSize(factory,
|
||||||
serverProperties.getMaxHttpHeaderSize());
|
serverProperties.getMaxHttpHeaderSize());
|
||||||
}
|
}
|
||||||
if (serverProperties.getMaxHttpPostSize() > 0) {
|
if (this.maxHttpPostSize > 0) {
|
||||||
customizeMaxHttpPostSize(factory, serverProperties.getMaxHttpPostSize());
|
customizeMaxHttpPostSize(factory, this.maxHttpPostSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (serverProperties.getConnectionTimeout() != null) {
|
if (serverProperties.getConnectionTimeout() != null) {
|
||||||
|
|
@ -1404,13 +1449,13 @@ public class ServerProperties
|
||||||
|
|
||||||
private void customizeMaxHttpPostSize(
|
private void customizeMaxHttpPostSize(
|
||||||
UndertowEmbeddedServletContainerFactory factory,
|
UndertowEmbeddedServletContainerFactory factory,
|
||||||
final int maxHttpPostSize) {
|
final long maxHttpPostSize) {
|
||||||
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
|
factory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void customize(Builder builder) {
|
public void customize(Builder builder) {
|
||||||
builder.setServerOption(UndertowOptions.MAX_ENTITY_SIZE,
|
builder.setServerOption(UndertowOptions.MAX_ENTITY_SIZE,
|
||||||
(long) maxHttpPostSize);
|
maxHttpPostSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -310,7 +310,9 @@ public class ServerPropertiesTests {
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
map.put("server.maxHttpPostSize", "9999");
|
map.put("server.maxHttpPostSize", "9999");
|
||||||
bindProperties(map);
|
bindProperties(map);
|
||||||
assertThat(this.properties.getMaxHttpPostSize()).isEqualTo(9999);
|
assertThat(this.properties.getJetty().getMaxHttpPostSize()).isEqualTo(9999);
|
||||||
|
assertThat(this.properties.getTomcat().getMaxHttpPostSize()).isEqualTo(9999);
|
||||||
|
assertThat(this.properties.getUndertow().getMaxHttpPostSize()).isEqualTo(9999);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -476,6 +478,35 @@ public class ServerPropertiesTests {
|
||||||
.getProtocolHandler()).getMaxConnections()).isEqualTo(5);
|
.getProtocolHandler()).getMaxConnections()).isEqualTo(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void customTomcatMaxHttpPostSize() {
|
||||||
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
|
map.put("server.tomcat.max-http-post-size", "10000");
|
||||||
|
bindProperties(map);
|
||||||
|
|
||||||
|
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
|
||||||
|
this.properties.customize(container);
|
||||||
|
TomcatEmbeddedServletContainer embeddedContainer = (TomcatEmbeddedServletContainer) container
|
||||||
|
.getEmbeddedServletContainer();
|
||||||
|
assertThat(embeddedContainer.getTomcat().getConnector().getMaxPostSize())
|
||||||
|
.isEqualTo(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
public void customTomcatMaxHttpPostSizeWithDeprecatedProperty() {
|
||||||
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
|
map.put("server.max-http-post-size", "2000");
|
||||||
|
bindProperties(map);
|
||||||
|
|
||||||
|
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
|
||||||
|
this.properties.customize(container);
|
||||||
|
TomcatEmbeddedServletContainer embeddedContainer = (TomcatEmbeddedServletContainer) container
|
||||||
|
.getEmbeddedServletContainer();
|
||||||
|
assertThat(embeddedContainer.getTomcat().getConnector().getMaxPostSize())
|
||||||
|
.isEqualTo(2000);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void customizeUndertowAccessLog() {
|
public void customizeUndertowAccessLog() {
|
||||||
Map<String, String> map = new HashMap<String, String>();
|
Map<String, String> map = new HashMap<String, String>();
|
||||||
|
|
|
||||||
|
|
@ -154,11 +154,11 @@ content into your application; rather pick only the properties that you need.
|
||||||
server.context-path= # Context path of the application.
|
server.context-path= # Context path of the application.
|
||||||
server.display-name=application # Display name of the application.
|
server.display-name=application # Display name of the application.
|
||||||
server.max-http-header-size=0 # Maximum size in bytes of the HTTP message header.
|
server.max-http-header-size=0 # Maximum size in bytes of the HTTP message header.
|
||||||
server.max-http-post-size=0 # Maximum size in bytes of the HTTP post content.
|
|
||||||
server.error.include-stacktrace=never # When to include a "stacktrace" attribute.
|
server.error.include-stacktrace=never # When to include a "stacktrace" attribute.
|
||||||
server.error.path=/error # Path of the error controller.
|
server.error.path=/error # Path of the error controller.
|
||||||
server.error.whitelabel.enabled=true # Enable the default error page displayed in browsers in case of a server error.
|
server.error.whitelabel.enabled=true # Enable the default error page displayed in browsers in case of a server error.
|
||||||
server.jetty.acceptors= # Number of acceptor threads to use.
|
server.jetty.acceptors= # Number of acceptor threads to use.
|
||||||
|
server.jetty.max-http-post-size=0 # Maximum size in bytes of the HTTP post or put content.
|
||||||
server.jetty.selectors= # Number of selector threads to use.
|
server.jetty.selectors= # Number of selector threads to use.
|
||||||
server.jsp-servlet.class-name=org.apache.jasper.servlet.JspServlet # The class name of the JSP servlet.
|
server.jsp-servlet.class-name=org.apache.jasper.servlet.JspServlet # The class name of the JSP servlet.
|
||||||
server.jsp-servlet.init-parameters.*= # Init parameters used to configure the JSP servlet
|
server.jsp-servlet.init-parameters.*= # Init parameters used to configure the JSP servlet
|
||||||
|
|
@ -213,6 +213,7 @@ content into your application; rather pick only the properties that you need.
|
||||||
172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
|
172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
|
||||||
172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses.
|
172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses.
|
||||||
server.tomcat.max-connections= # Maximum number of connections that the server will accept and process at any given time.
|
server.tomcat.max-connections= # Maximum number of connections that the server will accept and process at any given time.
|
||||||
|
server.tomcat.max-http-post-size=0 # Maximum size in bytes of the HTTP post content.
|
||||||
server.tomcat.max-threads=0 # Maximum amount of worker threads.
|
server.tomcat.max-threads=0 # Maximum amount of worker threads.
|
||||||
server.tomcat.min-spare-threads=0 # Minimum amount of worker threads.
|
server.tomcat.min-spare-threads=0 # Minimum amount of worker threads.
|
||||||
server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value.
|
server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value.
|
||||||
|
|
@ -231,6 +232,7 @@ content into your application; rather pick only the properties that you need.
|
||||||
server.undertow.buffers-per-region= # Number of buffer per region.
|
server.undertow.buffers-per-region= # Number of buffer per region.
|
||||||
server.undertow.direct-buffers= # Allocate buffers outside the Java heap.
|
server.undertow.direct-buffers= # Allocate buffers outside the Java heap.
|
||||||
server.undertow.io-threads= # Number of I/O threads to create for the worker.
|
server.undertow.io-threads= # Number of I/O threads to create for the worker.
|
||||||
|
server.undertow.max-http-post-size=0 # Maximum size in bytes of the HTTP post content.
|
||||||
server.undertow.worker-threads= # Number of worker threads.
|
server.undertow.worker-threads= # Number of worker threads.
|
||||||
|
|
||||||
# FREEMARKER ({sc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{sc-ext}[FreeMarkerAutoConfiguration])
|
# FREEMARKER ({sc-spring-boot-autoconfigure}/freemarker/FreeMarkerAutoConfiguration.{sc-ext}[FreeMarkerAutoConfiguration])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue