Skip to content

Commit f81a2f4

Browse files
committed
Customize part count and header size using context properties
1 parent 11cadea commit f81a2f4

4 files changed

Lines changed: 44 additions & 0 deletions

File tree

server/configs/application.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ context.encryptionKey=@@encryptionKey@@
6565
#context.bypass2FA=true
6666
#context.workDirLocation=/path/to/desired/workDir
6767

68+
## Required as of Tomcat v10.1.42 to override significantly lower default for part count (10 vs. 1000)
69+
## Header size default changed from 10Kb to 512.
70+
context.maxConnectorPartCount=100
71+
#context.maxConnectorPartHeaderSize=512
72+
6873
## SMTP configuration
6974
mail.smtpHost=@@smtpHost@@
7075
mail.smtpPort=@@smtpPort@@

server/configs/webapps/embedded/config/application.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ mail.smtpUser=Anonymous
103103
#context.bypass2FA=true
104104
#context.workDirLocation=@@/path/to/desired/workDir@@
105105

106+
## Required as of Tomcat v10.1.42 to override significantly lower default for part count (10 vs. 1000)
107+
## Header size default changed from 10Kb to 512.
108+
context.maxConnectorPartCount=100
109+
#context.maxConnectorPartHeaderSize=512
110+
106111
## Other webapps to be deployed, most commonly to deliver a set of static files. The context path to deploy into is the
107112
## property name after the "context.additionalWebapps." prefix, and the value is the location of the webapp on disk
108113
#context.additionalWebapps.firstContextPath=@@/my/webapp/path@@

server/embedded/src/org/labkey/embedded/LabKeyServer.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.springframework.boot.autoconfigure.SpringBootApplication;
88
import org.springframework.boot.context.ApplicationPidFileWriter;
99
import org.springframework.boot.context.properties.ConfigurationProperties;
10+
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
1011
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
1112
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
1213
import org.springframework.context.annotation.Bean;
@@ -137,6 +138,14 @@ public WebServerFactoryCustomizer<TomcatServletWebServerFactory> customizer()
137138
return customizer -> customizer.setDisableMBeanRegistry(false);
138139
}
139140

141+
@Bean
142+
TomcatConnectorCustomizer connectorCustomizer() {
143+
return (connector) -> {
144+
connector.setMaxPartCount(contextSource().getMaxConnectorPartCount());
145+
connector.setMaxPartHeaderSize(contextSource().getMaxConnectorPartHeaderSize());
146+
};
147+
}
148+
140149
@Bean
141150
public TomcatServletWebServerFactory servletContainerFactory()
142151
{
@@ -149,6 +158,7 @@ public TomcatServletWebServerFactory servletContainerFactory()
149158
Connector httpConnector = new Connector();
150159
httpConnector.setScheme("http");
151160
httpConnector.setPort(contextProperties.getHttpPort());
161+
result.getTomcatConnectorCustomizers().forEach(customizer -> customizer.customize(httpConnector));
152162
result.addAdditionalTomcatConnectors(httpConnector);
153163
}
154164

@@ -446,6 +456,9 @@ public static class ContextProperties
446456
private Map<String, Map<String, Map<String, String>>> resources;
447457
private Map<String, String> additionalWebapps;
448458

459+
private Integer maxConnectorPartCount = 100;
460+
private Integer maxConnectorPartHeaderSize = 512;
461+
449462
public List<String> getDataSourceName()
450463
{
451464
return dataSourceName;
@@ -708,6 +721,26 @@ public void setAdditionalWebapps(Map<String, String> additionalWebapps)
708721
{
709722
this.additionalWebapps = additionalWebapps;
710723
}
724+
725+
public Integer getMaxConnectorPartCount()
726+
{
727+
return maxConnectorPartCount;
728+
}
729+
730+
public void setMaxConnectorPartCount(Integer maxConnectorPartCount)
731+
{
732+
this.maxConnectorPartCount = maxConnectorPartCount;
733+
}
734+
735+
public Integer getMaxConnectorPartHeaderSize()
736+
{
737+
return maxConnectorPartHeaderSize;
738+
}
739+
740+
public void setMaxConnectorPartHeaderSize(Integer maxConnectorPartHeaderSize)
741+
{
742+
this.maxConnectorPartHeaderSize = maxConnectorPartHeaderSize;
743+
}
711744
}
712745

713746
@Configuration

server/embedded/src/org/labkey/embedded/LabKeyTomcatServletWebServerFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public LabKeyTomcatServletWebServerFactory(LabKeyServer server)
3838

3939
addConnectorCustomizers(connector -> {
4040
LabKeyServer.TomcatProperties props = _server.tomcatProperties();
41+
_server.connectorCustomizer().customize(connector);
4142

4243
if (props.getUseBodyEncodingForURI() != null)
4344
{

0 commit comments

Comments
 (0)