Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
* @author Aurélien Leboulanger
* @author Brian Clozel
* @author Olivier Lamy
* @author Artsiom Yudovin
*/
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
public class ServerProperties {
Expand Down Expand Up @@ -359,6 +360,11 @@ public static class Tomcat {
*/
private int acceptCount = 0;

/**
* Maximum amount of request body to swallow.
*/
private int maxSwallowSize = 0;

/**
* Comma-separated list of additional patterns that match jars to ignore for TLD
* scanning. The special '?' and '*' characters can be used in the pattern to
Expand Down Expand Up @@ -503,6 +509,14 @@ public void setAcceptCount(int acceptCount) {
this.acceptCount = acceptCount;
}

public int getMaxSwallowSize() {
return this.maxSwallowSize;
}

public void setMaxSwallowSize(int maxSwallowSize) {
this.maxSwallowSize = maxSwallowSize;
}

public List<String> getAdditionalTldSkipPatterns() {
return this.additionalTldSkipPatterns;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @author Yulin Qin
* @author Stephane Nicoll
* @author Phillip Webb
* @author Artsiom Yudovin
* @since 2.0.0
*/
public class TomcatWebServerFactoryCustomizer implements
Expand Down Expand Up @@ -101,6 +102,9 @@ public void customize(ConfigurableTomcatWebServerFactory factory) {
.to((maxConnections) -> customizeMaxConnections(factory, maxConnections));
propertyMapper.from(tomcatProperties::getAcceptCount).when(this::isPositive)
.to((acceptCount) -> customizeAcceptCount(factory, acceptCount));
propertyMapper.from(tomcatProperties::getMaxSwallowSize)
.when((maxSwallowSize) -> maxSwallowSize != 0)
.to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
customizeStaticResources(factory);
customizeErrorReportValve(properties.getError(), factory);
}
Expand Down Expand Up @@ -266,4 +270,16 @@ private void customizeErrorReportValve(ErrorProperties error,
}
}

@SuppressWarnings("rawtypes")
private void customizeMaxSwallowSize(ConfigurableTomcatWebServerFactory factory,
int maxSwallowSize) {
factory.addConnectorCustomizers((connector) -> {
ProtocolHandler handler = connector.getProtocolHandler();
if (handler instanceof AbstractHttp11Protocol) {
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
protocol.setMaxSwallowSize(maxSwallowSize);
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* @author Eddú Meléndez
* @author Quinten De Swaef
* @author Venil Noronha
* @author Artsiom Yudovin
*/
public class ServerPropertiesTests {

Expand Down Expand Up @@ -91,6 +92,7 @@ public void testTomcatBinding() {
map.put("server.tomcat.remote-ip-header", "Remote-Ip");
map.put("server.tomcat.internal-proxies", "10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
map.put("server.tomcat.background-processor-delay", "10");
map.put("server.tomcat.max-swallow-size", "2");
bind(map);
ServerProperties.Tomcat tomcat = this.properties.getTomcat();
assertThat(tomcat.getAccesslog().getPattern()).isEqualTo("%h %t '%r' %s %b");
Expand All @@ -105,6 +107,7 @@ public void testTomcatBinding() {
.isEqualTo("10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
assertThat(tomcat.getBackgroundProcessorDelay())
.isEqualTo(Duration.ofSeconds(10));
assertThat(tomcat.getMaxSwallowSize()).isEqualTo(2);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.catalina.valves.RemoteIpValve;
import org.apache.catalina.webresources.StandardRoot;
import org.apache.coyote.AbstractProtocol;
import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -49,6 +50,7 @@
* @author Brian Clozel
* @author Phillip Webb
* @author Rob Tompkins
* @author Artsiom Yudovin
*/
public class TomcatWebServerFactoryCustomizerTests {

Expand All @@ -67,6 +69,14 @@ public void setup() {
this.serverProperties);
}

@Test
public void customMaxSwallowSize() {
bind("server.tomcat.max-swallow-size=10");
customizeAndRunServer((server) -> assertThat(((AbstractHttp11Protocol<?>) server
.getTomcat().getConnector().getProtocolHandler()).getMaxSwallowSize())
.isEqualTo(10));
}

@Test
public void customAcceptCount() {
bind("server.tomcat.accept-count=10");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ content into your application. Rather, pick only the properties that you need.
server.tomcat.resource.cache-ttl= # Time-to-live of the static resource cache.
server.tomcat.uri-encoding=UTF-8 # Character encoding to use to decode the URI.
server.tomcat.use-relative-redirects= # Whether HTTP 1.1 and later location headers generated by a call to sendRedirect will use relative or absolute redirects.
server.tomcat.max-swallow-size= # Maximum amount of request body to swallow.
server.undertow.accesslog.dir= # Undertow access log directory.
server.undertow.accesslog.enabled=false # Whether to enable the access log.
server.undertow.accesslog.pattern=common # Format pattern for access logs.
Expand Down