Skip to content

Commit 424ce21

Browse files
committed
Code tweaks and comments
1 parent 959677b commit 424ce21

File tree

3 files changed

+33
-40
lines changed

3 files changed

+33
-40
lines changed

java-http.ipr

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<option name="addBlankAfter" value="false" />
1010
</LanguageOptions>
1111
</component>
12+
<component name="GitScope">
13+
<option name="currentTabIndex" value="1" />
14+
<option name="modelData" value="[{&quot;targetBranchMap&quot;:{&quot;value&quot;:{&quot;/Users/bpontarelli/dev/inversoft/fusionauth/java-http&quot;:&quot;HEAD~5&quot;}},&quot;customTabName&quot;:&quot;HEAD~5&quot;}]" />
15+
</component>
1216
<component name="InspectionProjectProfileManager">
1317
<profile version="1.0">
1418
<option name="myName" value="Project Default" />
@@ -1409,31 +1413,6 @@
14091413
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="Java 21" project-jdk-type="JavaSDK">
14101414
<output url="file://$PROJECT_DIR$/out" />
14111415
</component>
1412-
<component name="ProjectRunConfigurationManager">
1413-
<configuration default="true" type="TestNG">
1414-
<shortenClasspath name="NONE" />
1415-
<useClassPathOnly />
1416-
<option name="SUITE_NAME" value="" />
1417-
<option name="PACKAGE_NAME" value="" />
1418-
<option name="MAIN_CLASS_NAME" value="" />
1419-
<option name="GROUP_NAME" value="" />
1420-
<option name="TEST_OBJECT" value="CLASS" />
1421-
<option name="VM_PARAMETERS" value="-ea --add-exports java.base/sun.security.x509=ALL-UNNAMED --add-exports java.base/sun.security.util=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED" />
1422-
<option name="PARAMETERS" value="" />
1423-
<option name="OUTPUT_DIRECTORY" value="" />
1424-
<option name="TEST_SEARCH_SCOPE">
1425-
<value defaultName="moduleWithDependencies" />
1426-
</option>
1427-
<option name="PROPERTIES_FILE" value="" />
1428-
<properties />
1429-
<listeners>
1430-
<listener class="io.fusionauth.http.BaseTest$TestListener" />
1431-
</listeners>
1432-
<method v="2">
1433-
<option name="Make" enabled="true" />
1434-
</method>
1435-
</configuration>
1436-
</component>
14371416
<component name="VcsDirectoryMappings">
14381417
<mapping directory="$PROJECT_DIR$" vcs="Git" />
14391418
</component>
@@ -1450,4 +1429,4 @@
14501429
</SOURCES>
14511430
</library>
14521431
</component>
1453-
</project>
1432+
</project>

src/main/java/io/fusionauth/http/server/Configurable.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,24 @@ default T withMaxPendingSocketConnections(int maxPendingSocketConnections) {
187187

188188
/**
189189
* Sets the maximum size of the HTTP request body by optionally per Content-Type. If this limit is exceeded, the connection will be closed.
190-
* Defaults to 128 Megabytes.
191190
* <p>
192-
* Set this to -1 to disable this limitation.
191+
* A key of "*" will be the default value if a key doesn't exist for the specific Content-Type. Additionally, you can specify wildcards
192+
* for subtypes of Content-Types such as "application/*". This will be used if the exact Content-Type key is not in the Map.
193+
* <p>
194+
* An example lookup for the Content-Type "application/x-www-form-urlencoded" is:
195+
* <ol>
196+
* <li>application/x-www-form-urlencoded</li>
197+
* <li>application/*</li>
198+
* <li>*</li>
199+
* </ol>
200+
* <p>
201+
* If you pass in a Map that does not contain a default size using the String "*", this will retain the default value set by java-http.
202+
* Similarly, the default value for "application/x-www-form-urlencoded" is also retained if the Mapp you provide does not contain that
203+
* key.
204+
* <p>
205+
* Set any value to -1 to disable this limitation.
206+
* <p>
207+
* Defaults to 128 Megabytes for the wildcard "*" and 10 Megabytes for "application/x-www-form-urlencoded".
193208
*
194209
* @param maxRequestBodySize a map specifying the maximum size in bytes for the HTTP request body by Content-Type
195210
* @return This.

src/main/java/io/fusionauth/http/server/HTTPServerConfiguration.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@
3333
* @author Brian Pontarelli
3434
*/
3535
public 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

Comments
 (0)