File tree Expand file tree Collapse file tree 4 files changed +48
-10
lines changed
spring-boot-project/spring-boot-autoconfigure/src
main/java/org/springframework/boot/autoconfigure/web
test/java/org/springframework/boot/autoconfigure/web Expand file tree Collapse file tree 4 files changed +48
-10
lines changed Original file line number Diff line number Diff line change 7373 * @author Florian Storz
7474 * @author Michael Weidmann
7575 * @author Lasse Wulff
76+ * @author Yanming Zhou
7677 * @since 1.0.0
7778 */
7879@ ConfigurationProperties (prefix = "server" , ignoreUnknownFields = true )
@@ -513,13 +514,11 @@ public static class Tomcat {
513514 */
514515 private DataSize maxHttpResponseHeaderSize = DataSize .ofKilobytes (8 );
515516
516- public DataSize getMaxHttpFormPostSize () {
517- return this .maxHttpFormPostSize ;
518- }
519-
520- public void setMaxHttpFormPostSize (DataSize maxHttpFormPostSize ) {
521- this .maxHttpFormPostSize = maxHttpFormPostSize ;
522- }
517+ /**
518+ * Maximum number of parameters (GET plus POST) that will be automatically parsed
519+ * by the container.
520+ */
521+ private Integer maxParameterCount ;
523522
524523 public Accesslog getAccesslog () {
525524 return this .accesslog ;
@@ -669,6 +668,22 @@ public void setMaxHttpResponseHeaderSize(DataSize maxHttpResponseHeaderSize) {
669668 this .maxHttpResponseHeaderSize = maxHttpResponseHeaderSize ;
670669 }
671670
671+ public DataSize getMaxHttpFormPostSize () {
672+ return this .maxHttpFormPostSize ;
673+ }
674+
675+ public void setMaxHttpFormPostSize (DataSize maxHttpFormPostSize ) {
676+ this .maxHttpFormPostSize = maxHttpFormPostSize ;
677+ }
678+
679+ public Integer getMaxParameterCount () {
680+ return this .maxParameterCount ;
681+ }
682+
683+ public void setMaxParameterCount (Integer maxParameterCount ) {
684+ this .maxParameterCount = maxParameterCount ;
685+ }
686+
672687 /**
673688 * Tomcat access log properties.
674689 */
Original file line number Diff line number Diff line change 6262 * @author Parviz Rozikov
6363 * @author Florian Storz
6464 * @author Michael Weidmann
65+ * @author Yanming Zhou
6566 * @since 2.0.0
6667 */
6768public class TomcatWebServerFactoryCustomizer
@@ -119,6 +120,9 @@ public void customize(ConfigurableTomcatWebServerFactory factory) {
119120 .asInt (DataSize ::toBytes )
120121 .when ((maxHttpFormPostSize ) -> maxHttpFormPostSize != 0 )
121122 .to ((maxHttpFormPostSize ) -> customizeMaxHttpFormPostSize (factory , maxHttpFormPostSize ));
123+ map .from (properties ::getMaxParameterCount )
124+ .whenNonNull ()
125+ .to ((maxParameterCount ) -> customizeMaxParameterCount (factory , maxParameterCount ));
122126 map .from (properties ::getAccesslog )
123127 .when (ServerProperties .Tomcat .Accesslog ::isEnabled )
124128 .to ((enabled ) -> customizeAccessLog (factory ));
@@ -292,6 +296,10 @@ private void customizeMaxHttpFormPostSize(ConfigurableTomcatWebServerFactory fac
292296 factory .addConnectorCustomizers ((connector ) -> connector .setMaxPostSize (maxHttpFormPostSize ));
293297 }
294298
299+ private void customizeMaxParameterCount (ConfigurableTomcatWebServerFactory factory , int maxParameterCount ) {
300+ factory .addConnectorCustomizers ((connector ) -> connector .setMaxParameterCount (maxParameterCount ));
301+ }
302+
295303 private void customizeAccessLog (ConfigurableTomcatWebServerFactory factory ) {
296304 ServerProperties .Tomcat tomcatProperties = this .serverProperties .getTomcat ();
297305 AccessLogValve valve = new AccessLogValve ();
Original file line number Diff line number Diff line change 6969 * @author Chris Bono
7070 * @author Parviz Rozikov
7171 * @author Lasse Wulff
72+ * @author Yanming Zhou
7273 */
7374@ DirtiesUrlFactories
7475class ServerPropertiesTests {
@@ -199,7 +200,7 @@ void testCustomizedMimeMapping() {
199200 }
200201
201202 @ Test
202- void testCustomizeUriEncoding () {
203+ void testCustomizeTomcatUriEncoding () {
203204 bind ("server.tomcat.uri-encoding" , "US-ASCII" );
204205 assertThat (this .properties .getTomcat ().getUriEncoding ()).isEqualTo (StandardCharsets .US_ASCII );
205206 }
@@ -235,17 +236,23 @@ void testCustomizeTomcatKeepAliveTimeoutWithInfinite() {
235236 }
236237
237238 @ Test
238- void customizeMaxKeepAliveRequests () {
239+ void testCustomizeTomcatMaxKeepAliveRequests () {
239240 bind ("server.tomcat.max-keep-alive-requests" , "200" );
240241 assertThat (this .properties .getTomcat ().getMaxKeepAliveRequests ()).isEqualTo (200 );
241242 }
242243
243244 @ Test
244- void customizeMaxKeepAliveRequestsWithInfinite () {
245+ void testCustomizeTomcatMaxKeepAliveRequestsWithInfinite () {
245246 bind ("server.tomcat.max-keep-alive-requests" , "-1" );
246247 assertThat (this .properties .getTomcat ().getMaxKeepAliveRequests ()).isEqualTo (-1 );
247248 }
248249
250+ @ Test
251+ void testCustomizeTomcatMaxParameterCount () {
252+ bind ("server.tomcat.max-parameter-count" , "100" );
253+ assertThat (this .properties .getTomcat ().getMaxParameterCount ()).isEqualTo (100 );
254+ }
255+
249256 @ Test
250257 void testCustomizeTomcatMinSpareThreads () {
251258 bind ("server.tomcat.threads.min-spare" , "10" );
Original file line number Diff line number Diff line change 5959 * @author Victor Mandujano
6060 * @author Parviz Rozikov
6161 * @author Moritz Halbritter
62+ * @author Yanming Zhou
6263 */
6364class TomcatWebServerFactoryCustomizerTests {
6465
@@ -194,6 +195,13 @@ void customMaxHttpRequestHeaderSize() {
194195 .isEqualTo (DataSize .ofMegabytes (10 ).toBytes ()));
195196 }
196197
198+ @ Test
199+ void customMaxParameterCount () {
200+ bind ("server.tomcat.max-parameter-count=100" );
201+ customizeAndRunServer (
202+ (server ) -> assertThat (server .getTomcat ().getConnector ().getMaxParameterCount ()).isEqualTo (100 ));
203+ }
204+
197205 @ Test
198206 void customMaxRequestHttpHeaderSizeIgnoredIfNegative () {
199207 bind ("server.max-http-request-header-size=-1" );
You can’t perform that action at this time.
0 commit comments