Skip to content

Commit b61b7b0

Browse files
committed
Merge pull request #18566 from rhamedy
* pr/18566: Rename `max-http-post-size` server property Closes gh-18566
2 parents 63f60fc + 81dc6e0 commit b61b7b0

File tree

5 files changed

+71
-25
lines changed

5 files changed

+71
-25
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
* @author Brian Clozel
5757
* @author Olivier Lamy
5858
* @author Chentao Qu
59+
* @author Rafiullah Hamedy
5960
* @since 1.0.0
6061
*/
6162
@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
@@ -335,14 +336,14 @@ public static class Tomcat {
335336
private int minSpareThreads = 10;
336337

337338
/**
338-
* Maximum size of the HTTP post content.
339+
* Maximum size of the HTTP message header.
339340
*/
340-
private DataSize maxHttpPostSize = DataSize.ofMegabytes(2);
341+
private DataSize maxHttpHeaderSize = DataSize.ofBytes(0);
341342

342343
/**
343-
* Maximum size of the HTTP message header.
344+
* Maximum size of the form content in any HTTP post request.
344345
*/
345-
private DataSize maxHttpHeaderSize = DataSize.ofBytes(0);
346+
private DataSize maxHttpFormPostSize = DataSize.ofMegabytes(2);
346347

347348
/**
348349
* Maximum amount of request body to swallow.
@@ -413,12 +414,23 @@ public void setMinSpareThreads(int minSpareThreads) {
413414
this.minSpareThreads = minSpareThreads;
414415
}
415416

417+
@Deprecated
418+
@DeprecatedConfigurationProperty(replacement = "server.tomcat.max-http-form-post-size")
416419
public DataSize getMaxHttpPostSize() {
417-
return this.maxHttpPostSize;
420+
return this.maxHttpFormPostSize;
418421
}
419422

423+
@Deprecated
420424
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
421-
this.maxHttpPostSize = maxHttpPostSize;
425+
this.maxHttpFormPostSize = maxHttpPostSize;
426+
}
427+
428+
public DataSize getMaxHttpFormPostSize() {
429+
return this.maxHttpFormPostSize;
430+
}
431+
432+
public void setMaxHttpFormPostSize(DataSize maxHttpFormPostSize) {
433+
this.maxHttpFormPostSize = maxHttpFormPostSize;
422434
}
423435

424436
public Accesslog getAccesslog() {
@@ -746,9 +758,9 @@ public static class Jetty {
746758
private final Accesslog accesslog = new Accesslog();
747759

748760
/**
749-
* Maximum size of the HTTP post or put content.
761+
* Maximum size of the form content in any HTTP post request.
750762
*/
751-
private DataSize maxHttpPostSize = DataSize.ofBytes(200000);
763+
private DataSize maxHttpFormPostSize = DataSize.ofBytes(200000);
752764

753765
/**
754766
* Number of acceptor threads to use. When the value is -1, the default, the
@@ -771,12 +783,23 @@ public Accesslog getAccesslog() {
771783
return this.accesslog;
772784
}
773785

786+
@Deprecated
787+
@DeprecatedConfigurationProperty(replacement = "server.jetty.max-http-form-post-size")
774788
public DataSize getMaxHttpPostSize() {
775-
return this.maxHttpPostSize;
789+
return this.maxHttpFormPostSize;
776790
}
777791

792+
@Deprecated
778793
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
779-
this.maxHttpPostSize = maxHttpPostSize;
794+
this.maxHttpFormPostSize = maxHttpPostSize;
795+
}
796+
797+
public DataSize getMaxHttpFormPostSize() {
798+
return this.maxHttpFormPostSize;
799+
}
800+
801+
public void setMaxHttpFormPostSize(DataSize maxHttpFormPostSize) {
802+
this.maxHttpFormPostSize = maxHttpFormPostSize;
780803
}
781804

782805
public Integer getAcceptors() {

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/JettyWebServerFactoryCustomizer.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
*
4545
* @author Brian Clozel
4646
* @author Phillip Webb
47+
* @author Rafiullah Hamedy
4748
* @since 2.0.0
4849
*/
4950
public class JettyWebServerFactoryCustomizer
@@ -74,8 +75,8 @@ public void customize(ConfigurableJettyWebServerFactory factory) {
7475
propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull().asInt(DataSize::toBytes)
7576
.when(this::isPositive).to((maxHttpHeaderSize) -> factory
7677
.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
77-
propertyMapper.from(jettyProperties::getMaxHttpPostSize).asInt(DataSize::toBytes).when(this::isPositive)
78-
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
78+
propertyMapper.from(jettyProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when(this::isPositive)
79+
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
7980
propertyMapper.from(properties::getConnectionTimeout).whenNonNull()
8081
.to((connectionTimeout) -> customizeIdleTimeout(factory, connectionTimeout));
8182
propertyMapper.from(jettyProperties::getConnectionIdleTimeout).whenNonNull()
@@ -106,24 +107,24 @@ private void customizeIdleTimeout(ConfigurableJettyWebServerFactory factory, Dur
106107
});
107108
}
108109

109-
private void customizeMaxHttpPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpPostSize) {
110+
private void customizeMaxHttpFormPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpFormPostSize) {
110111
factory.addServerCustomizers(new JettyServerCustomizer() {
111112

112113
@Override
113114
public void customize(Server server) {
114-
setHandlerMaxHttpPostSize(maxHttpPostSize, server.getHandlers());
115+
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, server.getHandlers());
115116
}
116117

117-
private void setHandlerMaxHttpPostSize(int maxHttpPostSize, Handler... handlers) {
118+
private void setHandlerMaxHttpFormPostSize(int maxHttpPostSize, Handler... handlers) {
118119
for (Handler handler : handlers) {
119120
if (handler instanceof ContextHandler) {
120-
((ContextHandler) handler).setMaxFormContentSize(maxHttpPostSize);
121+
((ContextHandler) handler).setMaxFormContentSize(maxHttpFormPostSize);
121122
}
122123
else if (handler instanceof HandlerWrapper) {
123-
setHandlerMaxHttpPostSize(maxHttpPostSize, ((HandlerWrapper) handler).getHandler());
124+
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, ((HandlerWrapper) handler).getHandler());
124125
}
125126
else if (handler instanceof HandlerCollection) {
126-
setHandlerMaxHttpPostSize(maxHttpPostSize, ((HandlerCollection) handler).getHandlers());
127+
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, ((HandlerCollection) handler).getHandlers());
127128
}
128129
}
129130
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* @author Phillip Webb
5050
* @author Artsiom Yudovin
5151
* @author Chentao Qu
52+
* @author Rafiullah Hamedy
5253
* @since 2.0.0
5354
*/
5455
public class TomcatWebServerFactoryCustomizer
@@ -86,9 +87,9 @@ public void customize(ConfigurableTomcatWebServerFactory factory) {
8687
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize));
8788
propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull().asInt(DataSize::toBytes)
8889
.to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
89-
propertyMapper.from(tomcatProperties::getMaxHttpPostSize).asInt(DataSize::toBytes)
90-
.when((maxHttpPostSize) -> maxHttpPostSize != 0)
91-
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
90+
propertyMapper.from(tomcatProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes)
91+
.when((maxHttpFormPostSize) -> maxHttpFormPostSize != 0)
92+
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
9293
propertyMapper.from(tomcatProperties::getAccesslog).when(ServerProperties.Tomcat.Accesslog::isEnabled)
9394
.to((enabled) -> customizeAccessLog(factory));
9495
propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding);
@@ -218,8 +219,8 @@ private void customizeMaxSwallowSize(ConfigurableTomcatWebServerFactory factory,
218219
});
219220
}
220221

221-
private void customizeMaxHttpPostSize(ConfigurableTomcatWebServerFactory factory, int maxHttpPostSize) {
222-
factory.addConnectorCustomizers((connector) -> connector.setMaxPostSize(maxHttpPostSize));
222+
private void customizeMaxHttpFormPostSize(ConfigurableTomcatWebServerFactory factory, int maxHttpFormPostSize) {
223+
factory.addConnectorCustomizers((connector) -> connector.setMaxPostSize(maxHttpFormPostSize));
223224
}
224225

225226
private void customizeAccessLog(ConfigurableTomcatWebServerFactory factory) {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
* @author Eddú Meléndez
7373
* @author Quinten De Swaef
7474
* @author Venil Noronha
75+
* @author Rafiullah Hamedy
7576
*/
7677
public class ServerPropertiesTests {
7778

@@ -219,6 +220,12 @@ public void tomcatMaxHttpPostSizeMatchesConnectorDefault() throws Exception {
219220
.isEqualTo(getDefaultConnector().getMaxPostSize());
220221
}
221222

223+
@Test
224+
public void tomcatMaxHttpFormPostSizeMatchesConnectorDefault() throws Exception {
225+
assertThat(this.properties.getTomcat().getMaxHttpFormPostSize().toBytes())
226+
.isEqualTo(getDefaultConnector().getMaxPostSize());
227+
}
228+
222229
@Test
223230
public void tomcatBackgroundProcessorDelayMatchesEngineDefault() {
224231
assertThat(this.properties.getTomcat().getBackgroundProcessorDelay())
@@ -256,7 +263,7 @@ public void tomcatInternalProxiesMatchesDefault() {
256263
}
257264

258265
@Test
259-
public void jettyMaxHttpPostSizeMatchesDefault() throws Exception {
266+
public void jettyMaxHttpFormPostSizeMatchesDefault() throws Exception {
260267
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);
261268
JettyWebServer jetty = (JettyWebServer) jettyFactory
262269
.getWebServer((ServletContextInitializer) (servletContext) -> servletContext
@@ -308,7 +315,7 @@ public void handleError(ClientHttpResponse response) throws IOException {
308315
assertThat(failure.get()).isNotNull();
309316
String message = failure.get().getCause().getMessage();
310317
int defaultMaxPostSize = Integer.valueOf(message.substring(message.lastIndexOf(' ')).trim());
311-
assertThat(this.properties.getJetty().getMaxHttpPostSize().toBytes()).isEqualTo(defaultMaxPostSize);
318+
assertThat(this.properties.getJetty().getMaxHttpFormPostSize().toBytes()).isEqualTo(defaultMaxPostSize);
312319
}
313320
finally {
314321
jetty.stop();

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
* @author Rob Tompkins
5050
* @author Artsiom Yudovin
5151
* @author Stephane Nicoll
52+
* @author Rafiullah Hamedy
5253
*/
5354
public class TomcatWebServerFactoryCustomizerTests {
5455

@@ -95,6 +96,12 @@ public void customDisableMaxHttpPostSize() {
9596
customizeAndRunServer((server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1));
9697
}
9798

99+
@Test
100+
public void customDisableMaxHttpFormPostSize() {
101+
bind("server.tomcat.max-http-form-post-size=-1");
102+
customizeAndRunServer((server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1));
103+
}
104+
98105
@Test
99106
public void customMaxConnections() {
100107
bind("server.tomcat.max-connections=5");
@@ -110,6 +117,13 @@ public void customMaxHttpPostSize() {
110117
(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
111118
}
112119

120+
@Test
121+
public void customMaxHttpFormPostSize() {
122+
bind("server.tomcat.max-http-form-post-size=10000");
123+
customizeAndRunServer(
124+
(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
125+
}
126+
113127
@Test
114128
public void customMaxHttpHeaderSize() {
115129
bind("server.max-http-header-size=1KB");

0 commit comments

Comments
 (0)