3333 * @author Brian Pontarelli
3434 */
3535public class HTTPServerConfiguration implements Configurable <HTTPServerConfiguration > {
36+ public static final Map <String , Integer > DefaultMaxSizes = Map .of (
37+ "*" , 128 * 1024 * 1024 , // 128 Megabytes
38+ "application/x-www-form-urlencoded" , 10 * 1024 * 1024 // 10 Megabytes
39+ );
40+
3641 private final List <HTTPListenerConfiguration > listeners = new ArrayList <>();
3742
43+ private final Map <String , Integer > maxRequestBodySize = new HashMap <>(DefaultMaxSizes );
44+
3845 private Path baseDir = Path .of ("" );
3946
4047 private int chunkedBufferSize = 4 * 1024 ; // 4 Kilobytes
@@ -59,10 +66,6 @@ public class HTTPServerConfiguration implements Configurable<HTTPServerConfigura
5966
6067 private int maxPendingSocketConnections = 250 ;
6168
62- private Map <String , Integer > maxRequestBodySize = Map .of (
63- "*" , 128 * 1024 * 1024 , // 128 Megabytes
64- "application/x-www-form-urlencoded" , 10 * 1024 * 1024 ); // 10 Megabytes
65-
6669 private int maxRequestHeaderSize = 128 * 1024 ; // 128 Kilobytes
6770
6871 private int maxRequestsPerConnection = 100_000 ; // 100,000
@@ -487,14 +490,10 @@ public HTTPServerConfiguration withMaxRequestBodySize(Map<String, Integer> maxRe
487490 }
488491 }
489492
490- // Keep existing default if one was not provided.
491- if (!maxRequestBodySize .containsKey ("*" )) {
492- Map <String , Integer > copy = new HashMap <>(maxRequestBodySize );
493- copy .put ("*" , maxRequestBodySize .get ("*" ));
494- maxRequestBodySize = copy ;
495- }
496-
497- this .maxRequestBodySize = maxRequestBodySize ;
493+ // This preserves the default values in the field definition if the incoming Map does not contain them. Otherwise, they are overridden
494+ this .maxRequestBodySize .clear ();
495+ this .maxRequestBodySize .putAll (DefaultMaxSizes );
496+ this .maxRequestBodySize .putAll (maxRequestBodySize );
498497 return this ;
499498 }
500499
0 commit comments