The com. package defines a high-level API for
building servers that support HTTP and HTTPS. The SimpleFileServer class
implements a simple HTTP-only file server intended for testing, development
and debugging purposes. A default implementation is provided via the
jwebserver tool and the main entry point of the module, which can
also be invoked with java -m jdk.httpserver.
The com. package specifies a Service Provider
Interface (SPI) for locating HTTP server implementations based on the
com.sun.net.httpserver API.
System properties used by the HTTP server API
The following is a list of JDK specific system properties used by the default HTTP server implementation in the JDK. Any properties below that take a numeric value assume the default value if given a string that does not parse as a number.
sun.net.httpserver.idleInterval (default: 30 sec)
Maximum duration in seconds which an idle connection is kept open. This timer
has an implementation specific granularity that may mean that idle connections are
closed later than the specified interval. Values less than or equal to zero are mapped
to the default setting.
jdk.httpserver.maxConnections (default: -1)
The maximum number of open connections at a time. This includes active and idle connections.
If zero or negative, then no limit is enforced.
sun.net.httpserver.maxIdleConnections (default: 200)
The maximum number of idle connections at a time. If set to zero or a negative value
then connections are closed after use.
sun.net.httpserver.drainAmount (default: 65536)
The maximum number of bytes that will be automatically read and discarded from a
request body that has not been completely consumed by its
HttpHandler. If the number of remaining
unread bytes are less than this limit then the connection will be put in the idle connection
cache. If not, then it will be closed.
sun.net.httpserver.maxReqHeaders (default: 200)
The maxiumum number of header fields accepted in a request. If this limit is exceeded
while the headers are being read, then the connection is terminated and the request ignored.
If the value is less than or equal to zero, then the default value is used.
sun.net.httpserver.maxReqHeaderSize (default: 393216 or 384kB)
The maximum header field section size that the server is prepared to accept.
This is computed as the sum of the size of the header name, plus
the size of the header value, plus an overhead of 32 bytes for
each field section line. The request line counts as a first field section line,
where the name is empty and the value is the whole line.
If this limit is exceeded while the headers are being read, then the connection
is terminated and the request ignored.
If the value is less than or equal to zero, there is no limit.
sun.net.httpserver.maxReqTime (default: -1)
The maximum time in milliseconds allowed to receive a request headers and body.
In practice, the actual time is a function of request size, network speed, and handler
processing delays. A value less than or equal to zero means the time is not limited.
If the limit is exceeded then the connection is terminated and the handler will receive a
java.. This timer has an implementation specific granularity
that may mean requests are aborted later than the specified interval.
sun.net.httpserver.maxRspTime (default: -1)
The maximum time in milliseconds allowed to receive a response headers and body.
In practice, the actual time is a function of response size, network speed, and handler
processing delays. A value less than or equal to zero means the time is not limited.
If the limit is exceeded then the connection is terminated and the handler will receive a
java.. This timer has an implementation specific granularity
that may mean responses are aborted later than the specified interval.
sun.net.httpserver.nodelay (default: false)
Boolean value, which if true, sets the TCP_NODELAY
socket option on all incoming connections.
sun.net.httpserver.pathMatcher (default:
pathPrefix)
The path matching scheme used to route requests to context handlers.
The property can be configured with one of the following values:
pathPrefix(default)- The request path must begin with the context path and all matching path segments must be identical. For instance, the context path
/foowould match request paths/foo,/foo/, and/foo/bar, but not/foobar.stringPrefix- The request path string must begin with the context path string. For instance, the context path
/foowould match request paths/foo,/foo/,/foo/bar, and/foobar.
In case of a blank or invalid value, the default will be used.
This property and the ability to restore the string prefix matching behavior may be removed in a future release.
API Note
The API and SPI in this module are designed and implemented to support a minimal HTTP server and simple HTTP semantics primarily.
Implementation Note
The default implementation of the HTTP server provided in this module is intended for simple usages like local testing, development, and debugging. Accordingly, the design and implementation of the server does not intend to be a full-featured, high performance HTTP server.
Implementation Note
Prior to JDK 26, in the JDK default implementation, the HttpExchange attribute map was
shared with the enclosing HttpContext.
Since JDK 26, by default, exchange attributes are per-exchange and the context attributes must
be accessed by calling getHttpContext()..
A new system property, jdk.httpserver.attributes (default value: "")
allows to revert this new behavior. Set this property to "context" to restore the pre JDK 26 behavior.
| Modifier and Type | Package and Description |
|---|---|
| exported package | com.
Provides a simple high-level Http server API, which can be used to build embedded HTTP servers. |
| exported package | com.
Provides a pluggable service provider interface, which allows the HTTP server implementation to be replaced with other implementations. |
| internal package | |
| internal package | |
| internal package |