Polish
This commit is contained in:
parent
4fcaa87426
commit
22c7546607
|
@ -17,6 +17,7 @@
|
||||||
package org.springframework.boot.autoconfigure.web.embedded;
|
package org.springframework.boot.autoconfigure.web.embedded;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.AbstractConnector;
|
import org.eclipse.jetty.server.AbstractConnector;
|
||||||
import org.eclipse.jetty.server.ConnectionFactory;
|
import org.eclipse.jetty.server.ConnectionFactory;
|
||||||
|
@ -76,8 +77,8 @@ public class JettyWebServerFactoryCustomizer implements
|
||||||
.to(factory::setSelectors);
|
.to(factory::setSelectors);
|
||||||
propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull()
|
propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull()
|
||||||
.asInt(DataSize::toBytes).when(this::isPositive)
|
.asInt(DataSize::toBytes).when(this::isPositive)
|
||||||
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory,
|
.to((maxHttpHeaderSize) -> factory.addServerCustomizers(
|
||||||
maxHttpHeaderSize));
|
new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
|
||||||
propertyMapper.from(jettyProperties::getMaxHttpPostSize).asInt(DataSize::toBytes)
|
propertyMapper.from(jettyProperties::getMaxHttpPostSize).asInt(DataSize::toBytes)
|
||||||
.when(this::isPositive)
|
.when(this::isPositive)
|
||||||
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory,
|
.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,
|
private void customizeMaxHttpPostSize(ConfigurableJettyWebServerFactory factory,
|
||||||
int maxHttpPostSize) {
|
int maxHttpPostSize) {
|
||||||
factory.addServerCustomizers(new JettyServerCustomizer() {
|
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
|
@Test
|
||||||
public void backsOffWithNoDataSource() {
|
public void backsOffWithNoDataSource() {
|
||||||
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
this.contextRunner.withUserConfiguration(TestConfiguration.class)
|
||||||
.run((context) -> {
|
.run((context) -> assertThat(context)
|
||||||
assertThat(context)
|
.doesNotHaveBean(JdbcRepositoryConfigExtension.class));
|
||||||
.doesNotHaveBean(JdbcRepositoryConfigExtension.class);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -42,9 +42,8 @@ public class JsonbAutoConfigurationWithNoProviderTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void jsonbBacksOffWhenThereIsNoProvider() {
|
public void jsonbBacksOffWhenThereIsNoProvider() {
|
||||||
this.contextRunner.run((context) -> {
|
this.contextRunner
|
||||||
assertThat(context).doesNotHaveBean(Jsonb.class);
|
.run((context) -> assertThat(context).doesNotHaveBean(Jsonb.class));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -592,9 +592,7 @@ public class HibernateJpaAutoConfigurationTests
|
||||||
@Bean
|
@Bean
|
||||||
public EntityManagerFactoryBuilderCustomizer asyncBootstrappingCustomizer(
|
public EntityManagerFactoryBuilderCustomizer asyncBootstrappingCustomizer(
|
||||||
ThreadPoolTaskExecutor executor) {
|
ThreadPoolTaskExecutor executor) {
|
||||||
return (builder) -> {
|
return (builder) -> builder.setBootstrapExecutor(executor);
|
||||||
builder.setBootstrapExecutor(executor);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,12 +73,10 @@ public class TomcatWebServerFactoryCustomizerTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void defaultsAreConsistent() {
|
public void defaultsAreConsistent() {
|
||||||
customizeAndRunServer((server) -> {
|
customizeAndRunServer((server) -> assertThat(((AbstractHttp11Protocol<?>) server
|
||||||
assertThat(((AbstractHttp11Protocol<?>) server.getTomcat().getConnector()
|
.getTomcat().getConnector().getProtocolHandler()).getMaxSwallowSize())
|
||||||
.getProtocolHandler()).getMaxSwallowSize())
|
.isEqualTo(this.serverProperties.getTomcat().getMaxSwallowSize()
|
||||||
.isEqualTo(this.serverProperties.getTomcat()
|
.toBytes()));
|
||||||
.getMaxSwallowSize().toBytes());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue