Skip to content

Commit 5ff8efe

Browse files
committed
Customize part count and header size using context properties
1 parent 85cb683 commit 5ff8efe

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

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+
## Tomcat v10.1.42 lowered the default for part count from 1000 to 10. Our default is now 100, but can be overridden here.
69+
## Header size default changed from 10Kb to 512, which is also our default.
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+
## Tomcat v10.1.42 lowered the default for part count from 1000 to 10. Our default is now 100, but can be overridden here.
107+
## Header size default changed from 10Kb to 512, which is also our default.
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;
@@ -147,6 +148,14 @@ public WebServerFactoryCustomizer<TomcatServletWebServerFactory> customizer()
147148
return customizer -> customizer.setDisableMBeanRegistry(false);
148149
}
149150

151+
@Bean
152+
TomcatConnectorCustomizer connectorCustomizer() {
153+
return (connector) -> {
154+
connector.setMaxPartCount(contextSource().getMaxConnectorPartCount());
155+
connector.setMaxPartHeaderSize(contextSource().getMaxConnectorPartHeaderSize());
156+
};
157+
}
158+
150159
@Bean
151160
public TomcatServletWebServerFactory servletContainerFactory()
152161
{
@@ -159,6 +168,7 @@ public TomcatServletWebServerFactory servletContainerFactory()
159168
Connector httpConnector = new Connector();
160169
httpConnector.setScheme("http");
161170
httpConnector.setPort(contextProperties.getHttpPort());
171+
result.getTomcatConnectorCustomizers().forEach(customizer -> customizer.customize(httpConnector));
162172
result.addAdditionalTomcatConnectors(httpConnector);
163173
}
164174

@@ -456,6 +466,9 @@ public static class ContextProperties
456466
private Map<String, Map<String, Map<String, String>>> resources;
457467
private Map<String, String> additionalWebapps;
458468

469+
private Integer maxConnectorPartCount = 100;
470+
private Integer maxConnectorPartHeaderSize = 512;
471+
459472
public List<String> getDataSourceName()
460473
{
461474
return dataSourceName;
@@ -718,6 +731,26 @@ public void setAdditionalWebapps(Map<String, String> additionalWebapps)
718731
{
719732
this.additionalWebapps = additionalWebapps;
720733
}
734+
735+
public Integer getMaxConnectorPartCount()
736+
{
737+
return maxConnectorPartCount;
738+
}
739+
740+
public void setMaxConnectorPartCount(Integer maxConnectorPartCount)
741+
{
742+
this.maxConnectorPartCount = maxConnectorPartCount;
743+
}
744+
745+
public Integer getMaxConnectorPartHeaderSize()
746+
{
747+
return maxConnectorPartHeaderSize;
748+
}
749+
750+
public void setMaxConnectorPartHeaderSize(Integer maxConnectorPartHeaderSize)
751+
{
752+
this.maxConnectorPartHeaderSize = maxConnectorPartHeaderSize;
753+
}
721754
}
722755

723756
@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)