Java System Properties
Quick Reference Guide


jdk.http.maxHeaderSize Java System Property

The jdk.http.maxHeaderSize java system property specifies the maximum response header size that the JDK HTTP implementations will accept.

Default Value

393216

The default value is 384kB (393216 bytes).

Overview of jdk.http.maxHeaderSize

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.

Related System Properties

Here are some other networking Java system properties:

Supported Since

Java has supported the jdk.http.maxHeaderSize system property since Java 8u431, 11.0.25, 17.0.13, 21.0.5, 23.0.1.

Setting jdk.http.maxHeaderSize on Startup

You 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

Setting / Reading jdk.http.maxHeaderSize at Runtime

You 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 setProperty may 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");
}