pull/14934/merge
Phillip Webb 6 years ago
parent 4fcaa87426
commit 22c7546607

@ -17,6 +17,7 @@
package org.springframework.boot.autoconfigure.web.embedded;
import java.time.Duration;
import java.util.Arrays;
import org.eclipse.jetty.server.AbstractConnector;
import org.eclipse.jetty.server.ConnectionFactory;
@ -76,8 +77,8 @@ public class JettyWebServerFactoryCustomizer implements
.to(factory::setSelectors);
propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull()
.asInt(DataSize::toBytes).when(this::isPositive)
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
maxHttpHeaderSize));
.to((maxHttpHeaderSize) -> factory.addServerCustomizers(
new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
propertyMapper.from(jettyProperties::getMaxHttpPostSize).asInt(DataSize::toBytes)
.when(this::isPositive)
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory,
@ -115,32 +116,6 @@ public class JettyWebServerFactoryCustomizer implements
});
}
private void customizeMaxHttpHeaderSize(ConfigurableJettyWebServerFactory factory,
int maxHttpHeaderSize) {
factory.addServerCustomizers(new JettyServerCustomizer() {
@Override
public void customize(Server server) {
for (org.eclipse.jetty.server.Connector connector : server
.getConnectors()) {
for (ConnectionFactory connectionFactory : connector
.getConnectionFactories()) {
if (connectionFactory instanceof HttpConfiguration.ConnectionFactory) {
customize(
(HttpConfiguration.ConnectionFactory) connectionFactory);
}
}
}
}
private void customize(HttpConfiguration.ConnectionFactory factory) {
HttpConfiguration configuration = factory.getHttpConfiguration();
configuration.setRequestHeaderSize(maxHttpHeaderSize);
}
});
}
private void customizeMaxHttpPostSize(ConfigurableJettyWebServerFactory factory,
int maxHttpPostSize) {
factory.addServerCustomizers(new JettyServerCustomizer() {
@ -199,4 +174,30 @@ public class JettyWebServerFactoryCustomizer implements
});
}
private static class MaxHttpHeaderSizeCustomizer implements JettyServerCustomizer {
private final int maxHttpHeaderSize;
MaxHttpHeaderSizeCustomizer(int maxHttpHeaderSize) {
this.maxHttpHeaderSize = maxHttpHeaderSize;
}
@Override
public void customize(Server server) {
Arrays.stream(server.getConnectors()).forEach(this::customize);
}
private void customize(org.eclipse.jetty.server.Connector connector) {
connector.getConnectionFactories().forEach(this::customize);
}
private void customize(ConnectionFactory factory) {
if (factory instanceof HttpConfiguration.ConnectionFactory) {
((HttpConfiguration.ConnectionFactory) factory).getHttpConfiguration()
.setRequestHeaderSize(this.maxHttpHeaderSize);
}
}
}
}

@ -51,10 +51,8 @@ public class JdbcRepositoriesAutoConfigurationTests {
@Test
public void backsOffWithNoDataSource() {
this.contextRunner.withUserConfiguration(TestConfiguration.class)
.run((context) -> {
assertThat(context)
.doesNotHaveBean(JdbcRepositoryConfigExtension.class);
});
.run((context) -> assertThat(context)
.doesNotHaveBean(JdbcRepositoryConfigExtension.class));
}
@Test

@ -42,9 +42,8 @@ public class JsonbAutoConfigurationWithNoProviderTests {
@Test
public void jsonbBacksOffWhenThereIsNoProvider() {
this.contextRunner.run((context) -> {
assertThat(context).doesNotHaveBean(Jsonb.class);
});
this.contextRunner
.run((context) -> assertThat(context).doesNotHaveBean(Jsonb.class));
}
}

@ -592,9 +592,7 @@ public class HibernateJpaAutoConfigurationTests
@Bean
public EntityManagerFactoryBuilderCustomizer asyncBootstrappingCustomizer(
ThreadPoolTaskExecutor executor) {
return (builder) -> {
builder.setBootstrapExecutor(executor);
};
return (builder) -> builder.setBootstrapExecutor(executor);
}
}

@ -73,12 +73,10 @@ public class TomcatWebServerFactoryCustomizerTests {
@Test
public void defaultsAreConsistent() {
customizeAndRunServer((server) -> {
assertThat(((AbstractHttp11Protocol<?>) server.getTomcat().getConnector()
.getProtocolHandler()).getMaxSwallowSize())
.isEqualTo(this.serverProperties.getTomcat()
.getMaxSwallowSize().toBytes());
});
customizeAndRunServer((server) -> assertThat(((AbstractHttp11Protocol<?>) server
.getTomcat().getConnector().getProtocolHandler()).getMaxSwallowSize())
.isEqualTo(this.serverProperties.getTomcat().getMaxSwallowSize()
.toBytes()));
}
@Test

Loading…
Cancel
Save