The default value is 384kB (393216 bytes).
The jdk.http.maxHeaderSize system property controls the maximum response header size that the JDK built-in HTTP implementations will accept from a remote party. This applies to both the legacy HttpURLConnection and the new (as of Java 11) java.net.http.HttpClient.
The size is computed as the cumulative size of all header names and header values, plus an overhead of 32 bytes per header name/value pair.
A positive value sets the maximum header size in bytes. A negative or zero value is interpreted as no limit. If the limit is exceeded, the request will fail with a protocol exception.
The value can also be specified in the $JAVA_HOME/conf/net.properties file.
Here are some other networking Java system properties:
http.agenthttp.keepAlivehttp.maxConnectionshttps.protocolsjava.net.preferIPv4Stackjava.net.preferIPv6Addressesjava.net.useSystemProxiesjavax.net.debugjavax.net.ssl.trustStorejdk.net.hosts.filejdk.tls.client.protocolsjdk.tls.server.newSessionTicketCountjdk.crypto.disabledAlgorithmsjdk.tls.disabledAlgorithmsnetworkaddress.cache.negative.ttlnetworkaddress.cache.ttlsun.net.client.defaultConnectTimeoutsun.net.client.defaultReadTimeoutsun.net.inetaddr.ttlJava has supported the jdk.http.maxHeaderSize system property since Java 8u431, 11.0.25, 17.0.13, 21.0.5, 23.0.1.
jdk.http.maxHeaderSize on StartupYou can set the jdk.http.maxHeaderSize java system property during startup of the java runtime using the -D command line argument:
java -Djdk.http.maxHeaderSize=393216 MyAppMain
You may also be able to specify jdk.http.maxHeaderSize via the JAVA_TOOL_OPTIONS environment variable:
JAVA_TOOL_OPTIONS=-Djdk.http.maxHeaderSize=393216
jdk.http.maxHeaderSize at RuntimeYou can set jdk.http.maxHeaderSize at runtime with the following Java code:
System.setProperty("jdk.http.maxHeaderSize", "393216");
WARNING: Depending on the property and JVM version using
setPropertymay or may not work if the JDK Java class that uses this variable has already been loaded. The value of the jdk.http.maxHeaderSize system property may be cached within an internal private static variable of the implementing class.
To read the value of jdk.http.maxHeaderSize at runtime, you can use this Java code:
String propertyValue = System.getProperty("jdk.http.maxHeaderSize");
if (propertyValue != null) {
System.out.println("jdk.http.maxHeaderSize = " + propertyValue);
} else {
System.out.println("jdk.http.maxHeaderSize was null");
}