mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Allow the tomcat maxHttpHeaderSize to be changed in external config
Prevents large SPNEGO headers from causing server errors for example. Added the property to ServerProperties. Fixes gh-931
This commit is contained in:
parent
0e2f9e74db
commit
dfc1979ea2
@ -27,6 +27,7 @@ import org.apache.catalina.valves.AccessLogValve;
|
||||
import org.apache.catalina.valves.RemoteIpValve;
|
||||
import org.apache.coyote.AbstractProtocol;
|
||||
import org.apache.coyote.ProtocolHandler;
|
||||
import org.apache.coyote.http11.AbstractHttp11Protocol;
|
||||
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
|
||||
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor;
|
||||
@ -41,7 +42,7 @@ import org.springframework.util.StringUtils;
|
||||
* {@link ConfigurationProperties properties} for a web server (e.g. port and path
|
||||
* settings). Will be used to customize an {@link EmbeddedServletContainerFactory} when an
|
||||
* {@link EmbeddedServletContainerCustomizerBeanPostProcessor} is active.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ -145,6 +146,8 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
|
||||
|
||||
private int maxThreads = 0; // Number of threads in protocol handler
|
||||
|
||||
private int maxHttpHeaderSize = 0; // bytes
|
||||
|
||||
private String uriEncoding;
|
||||
|
||||
public int getMaxThreads() {
|
||||
@ -155,6 +158,14 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
|
||||
this.maxThreads = maxThreads;
|
||||
}
|
||||
|
||||
public int getMaxHttpHeaderSize() {
|
||||
return maxHttpHeaderSize;
|
||||
}
|
||||
|
||||
public void setMaxHttpHeaderSize(int maxHttpHeaderSize) {
|
||||
this.maxHttpHeaderSize = maxHttpHeaderSize;
|
||||
}
|
||||
|
||||
public boolean getAccessLogEnabled() {
|
||||
return this.accessLogEnabled;
|
||||
}
|
||||
@ -246,6 +257,19 @@ public class ServerProperties implements EmbeddedServletContainerCustomizer {
|
||||
});
|
||||
}
|
||||
|
||||
if (this.maxHttpHeaderSize > 0) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractHttp11Protocol) {
|
||||
AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) handler;
|
||||
protocol.setMaxHttpHeaderSize(Tomcat.this.maxHttpHeaderSize);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (this.accessLogEnabled) {
|
||||
AccessLogValve valve = new AccessLogValve();
|
||||
String accessLogPattern = getAccessLogPattern();
|
||||
|
@ -34,7 +34,7 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests for {@link ServerProperties}.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ -97,4 +97,13 @@ public class ServerPropertiesTests {
|
||||
assertEquals("US-ASCII", this.properties.getTomcat().getUriEncoding());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomizeTomcatHeaderSize() throws Exception {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("server.tomcat.maxHttpHeaderSize", "9999");
|
||||
new RelaxedDataBinder(this.properties, "server").bind(new MutablePropertyValues(
|
||||
map));
|
||||
assertEquals(9999, this.properties.getTomcat().getMaxHttpHeaderSize());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user