Skip to content

Commit 511a2a0

Browse files
committed
Merge branch '2.1.x'
Closes gh-18695
2 parents 83d4d94 + b61b7b0 commit 511a2a0

File tree

5 files changed

+68
-23
lines changed

5 files changed

+68
-23
lines changed

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ public static class Tomcat {
359359
private int minSpareThreads = 10;
360360

361361
/**
362-
* Maximum size of the HTTP post content.
362+
* Maximum size of the form content in any HTTP post request.
363363
*/
364-
private DataSize maxHttpPostSize = DataSize.ofMegabytes(2);
364+
private DataSize maxHttpFormPostSize = DataSize.ofMegabytes(2);
365365

366366
/**
367367
* Maximum amount of request body to swallow.
@@ -456,12 +456,23 @@ public void setMinSpareThreads(int minSpareThreads) {
456456
this.minSpareThreads = minSpareThreads;
457457
}
458458

459+
@Deprecated
460+
@DeprecatedConfigurationProperty(replacement = "server.tomcat.max-http-form-post-size")
459461
public DataSize getMaxHttpPostSize() {
460-
return this.maxHttpPostSize;
462+
return this.maxHttpFormPostSize;
461463
}
462464

465+
@Deprecated
463466
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
464-
this.maxHttpPostSize = maxHttpPostSize;
467+
this.maxHttpFormPostSize = maxHttpPostSize;
468+
}
469+
470+
public DataSize getMaxHttpFormPostSize() {
471+
return this.maxHttpFormPostSize;
472+
}
473+
474+
public void setMaxHttpFormPostSize(DataSize maxHttpFormPostSize) {
475+
this.maxHttpFormPostSize = maxHttpFormPostSize;
465476
}
466477

467478
public Accesslog getAccesslog() {
@@ -927,9 +938,9 @@ public static class Jetty {
927938
private final Accesslog accesslog = new Accesslog();
928939

929940
/**
930-
* Maximum size of the HTTP post or put content.
941+
* Maximum size of the form content in any HTTP post request.
931942
*/
932-
private DataSize maxHttpPostSize = DataSize.ofBytes(200000);
943+
private DataSize maxHttpFormPostSize = DataSize.ofBytes(200000);
933944

934945
/**
935946
* Number of acceptor threads to use. When the value is -1, the default, the
@@ -967,12 +978,23 @@ public Accesslog getAccesslog() {
967978
return this.accesslog;
968979
}
969980

981+
@Deprecated
982+
@DeprecatedConfigurationProperty(replacement = "server.jetty.max-http-form-post-size")
970983
public DataSize getMaxHttpPostSize() {
971-
return this.maxHttpPostSize;
984+
return this.maxHttpFormPostSize;
972985
}
973986

987+
@Deprecated
974988
public void setMaxHttpPostSize(DataSize maxHttpPostSize) {
975-
this.maxHttpPostSize = maxHttpPostSize;
989+
this.maxHttpFormPostSize = maxHttpPostSize;
990+
}
991+
992+
public DataSize getMaxHttpFormPostSize() {
993+
return this.maxHttpFormPostSize;
994+
}
995+
996+
public void setMaxHttpFormPostSize(DataSize maxHttpFormPostSize) {
997+
this.maxHttpFormPostSize = maxHttpFormPostSize;
976998
}
977999

9781000
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
@@ -50,6 +50,7 @@
5050
* @author Brian Clozel
5151
* @author Phillip Webb
5252
* @author HaiTao Zhang
53+
* @author Rafiullah Hamedy
5354
* @since 2.0.0
5455
*/
5556
public class JettyWebServerFactoryCustomizer
@@ -80,8 +81,8 @@ public void customize(ConfigurableJettyWebServerFactory factory) {
8081
propertyMapper.from(properties::getMaxHttpHeaderSize).whenNonNull().asInt(DataSize::toBytes)
8182
.when(this::isPositive).to((maxHttpHeaderSize) -> factory
8283
.addServerCustomizers(new MaxHttpHeaderSizeCustomizer(maxHttpHeaderSize)));
83-
propertyMapper.from(jettyProperties::getMaxHttpPostSize).asInt(DataSize::toBytes).when(this::isPositive)
84-
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
84+
propertyMapper.from(jettyProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes).when(this::isPositive)
85+
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
8586
propertyMapper.from(jettyProperties::getMaxThreads).when(this::isPositive)
8687
.to((maxThreads) -> customizeThreadPool(factory, (threadPool) -> threadPool.setMaxThreads(maxThreads)));
8788
propertyMapper.from(jettyProperties::getMinThreads).when(this::isPositive)
@@ -118,24 +119,24 @@ private void customizeIdleTimeout(ConfigurableJettyWebServerFactory factory, Dur
118119
});
119120
}
120121

121-
private void customizeMaxHttpPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpPostSize) {
122+
private void customizeMaxHttpFormPostSize(ConfigurableJettyWebServerFactory factory, int maxHttpFormPostSize) {
122123
factory.addServerCustomizers(new JettyServerCustomizer() {
123124

124125
@Override
125126
public void customize(Server server) {
126-
setHandlerMaxHttpPostSize(maxHttpPostSize, server.getHandlers());
127+
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, server.getHandlers());
127128
}
128129

129-
private void setHandlerMaxHttpPostSize(int maxHttpPostSize, Handler... handlers) {
130+
private void setHandlerMaxHttpFormPostSize(int maxHttpPostSize, Handler... handlers) {
130131
for (Handler handler : handlers) {
131132
if (handler instanceof ContextHandler) {
132-
((ContextHandler) handler).setMaxFormContentSize(maxHttpPostSize);
133+
((ContextHandler) handler).setMaxFormContentSize(maxHttpFormPostSize);
133134
}
134135
else if (handler instanceof HandlerWrapper) {
135-
setHandlerMaxHttpPostSize(maxHttpPostSize, ((HandlerWrapper) handler).getHandler());
136+
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, ((HandlerWrapper) handler).getHandler());
136137
}
137138
else if (handler instanceof HandlerCollection) {
138-
setHandlerMaxHttpPostSize(maxHttpPostSize, ((HandlerCollection) handler).getHandlers());
139+
setHandlerMaxHttpFormPostSize(maxHttpFormPostSize, ((HandlerCollection) handler).getHandlers());
139140
}
140141
}
141142
}

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
@@ -54,6 +54,7 @@
5454
* @author Chentao Qu
5555
* @author Andrew McGhie
5656
* @author Dirk Deyne
57+
* @author Rafiullah Hamedy
5758
* @since 2.0.0
5859
*/
5960
public class TomcatWebServerFactoryCustomizer
@@ -91,9 +92,9 @@ public void customize(ConfigurableTomcatWebServerFactory factory) {
9192
.to((maxHttpHeaderSize) -> customizeMaxHttpHeaderSize(factory, maxHttpHeaderSize));
9293
propertyMapper.from(tomcatProperties::getMaxSwallowSize).whenNonNull().asInt(DataSize::toBytes)
9394
.to((maxSwallowSize) -> customizeMaxSwallowSize(factory, maxSwallowSize));
94-
propertyMapper.from(tomcatProperties::getMaxHttpPostSize).asInt(DataSize::toBytes)
95-
.when((maxHttpPostSize) -> maxHttpPostSize != 0)
96-
.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, maxHttpPostSize));
95+
propertyMapper.from(tomcatProperties::getMaxHttpFormPostSize).asInt(DataSize::toBytes)
96+
.when((maxHttpFormPostSize) -> maxHttpFormPostSize != 0)
97+
.to((maxHttpFormPostSize) -> customizeMaxHttpFormPostSize(factory, maxHttpFormPostSize));
9798
propertyMapper.from(tomcatProperties::getAccesslog).when(ServerProperties.Tomcat.Accesslog::isEnabled)
9899
.to((enabled) -> customizeAccessLog(factory));
99100
propertyMapper.from(tomcatProperties::getUriEncoding).whenNonNull().to(factory::setUriEncoding);
@@ -244,8 +245,8 @@ private void customizeMaxSwallowSize(ConfigurableTomcatWebServerFactory factory,
244245
});
245246
}
246247

247-
private void customizeMaxHttpPostSize(ConfigurableTomcatWebServerFactory factory, int maxHttpPostSize) {
248-
factory.addConnectorCustomizers((connector) -> connector.setMaxPostSize(maxHttpPostSize));
248+
private void customizeMaxHttpFormPostSize(ConfigurableTomcatWebServerFactory factory, int maxHttpFormPostSize) {
249+
factory.addConnectorCustomizers((connector) -> connector.setMaxPostSize(maxHttpFormPostSize));
249250
}
250251

251252
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
@@ -75,6 +75,7 @@
7575
* @author Venil Noronha
7676
* @author Andrew McGhie
7777
* @author HaiTao Zhang
78+
* @author Rafiullah Hamedy
7879
*/
7980
class ServerPropertiesTests {
8081

@@ -310,6 +311,12 @@ void tomcatBackgroundProcessorDelayMatchesEngineDefault() {
310311
.isEqualTo(Duration.ofSeconds((new StandardEngine().getBackgroundProcessorDelay())));
311312
}
312313

314+
@Test
315+
void tomcatMaxHttpFormPostSizeMatchesConnectorDefault() throws Exception {
316+
assertThat(this.properties.getTomcat().getMaxHttpFormPostSize().toBytes())
317+
.isEqualTo(getDefaultConnector().getMaxPostSize());
318+
}
319+
313320
@Test
314321
void tomcatUriEncodingMatchesConnectorDefault() throws Exception {
315322
assertThat(this.properties.getTomcat().getUriEncoding().name())
@@ -341,7 +348,7 @@ void tomcatInternalProxiesMatchesDefault() {
341348
}
342349

343350
@Test
344-
void jettyMaxHttpPostSizeMatchesDefault() throws Exception {
351+
void jettyMaxHttpFormPostSizeMatchesDefault() throws Exception {
345352
JettyServletWebServerFactory jettyFactory = new JettyServletWebServerFactory(0);
346353
JettyWebServer jetty = (JettyWebServer) jettyFactory
347354
.getWebServer((ServletContextInitializer) (servletContext) -> servletContext
@@ -393,7 +400,7 @@ public void handleError(ClientHttpResponse response) throws IOException {
393400
assertThat(failure.get()).isNotNull();
394401
String message = failure.get().getCause().getMessage();
395402
int defaultMaxPostSize = Integer.valueOf(message.substring(message.lastIndexOf(' ')).trim());
396-
assertThat(this.properties.getJetty().getMaxHttpPostSize().toBytes()).isEqualTo(defaultMaxPostSize);
403+
assertThat(this.properties.getJetty().getMaxHttpFormPostSize().toBytes()).isEqualTo(defaultMaxPostSize);
397404
}
398405
finally {
399406
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
@@ -52,6 +52,7 @@
5252
* @author Artsiom Yudovin
5353
* @author Stephane Nicoll
5454
* @author Andrew McGhie
55+
* @author Rafiullah Hamedy
5556
*/
5657
class TomcatWebServerFactoryCustomizerTests {
5758

@@ -114,6 +115,12 @@ void customDisableMaxHttpPostSize() {
114115
customizeAndRunServer((server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1));
115116
}
116117

118+
@Test
119+
void customDisableMaxHttpFormPostSize() {
120+
bind("server.tomcat.max-http-form-post-size=-1");
121+
customizeAndRunServer((server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(-1));
122+
}
123+
117124
@Test
118125
void customMaxConnections() {
119126
bind("server.tomcat.max-connections=5");
@@ -129,6 +136,13 @@ void customMaxHttpPostSize() {
129136
(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
130137
}
131138

139+
@Test
140+
void customMaxHttpFormPostSize() {
141+
bind("server.tomcat.max-http-form-post-size=10000");
142+
customizeAndRunServer(
143+
(server) -> assertThat(server.getTomcat().getConnector().getMaxPostSize()).isEqualTo(10000));
144+
}
145+
132146
@Test
133147
void customMaxHttpHeaderSize() {
134148
bind("server.max-http-header-size=1KB");

0 commit comments

Comments
 (0)