Restore max-http-header-size default value support

Fix `TomcatWebServerFactoryCustomizer` to restore Spring Boot 2.0
behavior where a negative or zero `max-http-header-size` indicates
that the server default should be used.

See gh-14986
This commit is contained in:
Bryan Turner 2018-10-28 14:43:18 -07:00 committed by Phillip Webb
parent 807743b679
commit 8b40ce14cb
2 changed files with 17 additions and 1 deletions

View File

@ -86,7 +86,7 @@ public class TomcatWebServerFactoryCustomizer implements
propertyMapper.from(tomcatProperties::getMinSpareThreads).when(this::isPositive)
.to((minSpareThreads) -> customizeMinThreads(factory, minSpareThreads));
propertyMapper.from(this::determineMaxHttpHeaderSize).whenNonNull()
.asInt(DataSize::toBytes)
.asInt(DataSize::toBytes).when(this::isPositive)
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
maxHttpHeaderSize));
propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull()

View File

@ -129,6 +129,22 @@ public class TomcatWebServerFactoryCustomizerTests {
.isEqualTo(DataSize.ofKilobytes(1).toBytes()));
}
@Test
public void customMaxHttpHeaderSizeIgnoredIfNegative() {
bind("server.max-http-header-size=-1");
customizeAndRunServer((server) -> assertThat(((AbstractHttp11Protocol<?>) server
.getTomcat().getConnector().getProtocolHandler()).getMaxHttpHeaderSize())
.isEqualTo(DataSize.ofKilobytes(8).toBytes()));
}
@Test
public void customMaxHttpHeaderSizeIgnoredIfZero() {
bind("server.max-http-header-size=0");
customizeAndRunServer((server) -> assertThat(((AbstractHttp11Protocol<?>) server
.getTomcat().getConnector().getProtocolHandler()).getMaxHttpHeaderSize())
.isEqualTo(DataSize.ofKilobytes(8).toBytes()));
}
@Test
@Deprecated
public void customMaxHttpHeaderSizeWithDeprecatedProperty() {