|
|
@ -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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|