Class RequestDecompressionPolicy
java.lang.Object
com.soklet.RequestDecompressionPolicy
Policy used by the standard HTTP server to decide whether and how gzip-compressed request bodies
(
Content-Encoding: gzip or x-gzip, per
RFC 9110, Section 8.4) are
transparently decompressed before request handling. Only a single gzip/x-gzip coding is
supported; coding chains (e.g. identity, gzip) are rejected with 415 as sanctioned by
RFC 9110, Section 15.5.16.
Decompression is opt-in and disabled by default; see
HttpServer.Builder#requestDecompressionPolicy(RequestDecompressionPolicy). When disabled, request
bodies are passed to handlers exactly as received, compressed or not.
When enabled:
- A request with
Content-Encoding: gziporx-gziphas its body decompressed; theContent-Encodingheader is removed andContent-Lengthis updated to the decompressed size, so handlers observe a self-consistent uncompressed request. The original encoded payload size remains available throughRequest.getEncodedBodySizeInBytes()for telemetry and diagnostics. - A request with an unsupported
Content-Encoding(or multiple codings) is rejected with415 Unsupported Media Type. - A request whose body cannot be decompressed is rejected with
400 Bad Request. - A request whose decompressed body exceeds
getMaximumDecompressedBodySizeInBytes()(or, when unset, the server'smaximumRequestSizeInBytes) or expands beyondgetMaximumCompressionRatio()is rejected through the normal413 Content Too Largemarshaling path. These limits guard against decompression bombs; decompression aborts as soon as a limit is exceeded. Content-Encoding: identity, requests withoutContent-Encoding, and bodylessgzip/x-gziprequests are passed through unchanged.
This applies to the standard HTTP server only. The SSE and MCP servers do not decompress request bodies,
and the Simulator exercises handlers directly without transport-level decompression.
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for enabledRequestDecompressionPolicyinstances. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Acquires a builder for an enabled request decompression policy with custom limits.Acquires a policy that disables request decompression (the default): request bodies are passed to handlers exactly as received.Acquires a policy that enables gzip request decompression with default limits: the decompressed body is capped by the server'smaximumRequestSizeInBytesand a100:1compression ratio.The maximum permitted expansion ratio between decompressed and compressed body sizes.The maximum permitted decompressed body size in bytes, if customized.Is request decompression enabled?toString()
-
Method Details
-
disabledInstance
Acquires a policy that disables request decompression (the default): request bodies are passed to handlers exactly as received.- Returns:
- a disabled request decompression policy
-
fromDefaults
Acquires a policy that enables gzip request decompression with default limits: the decompressed body is capped by the server'smaximumRequestSizeInBytesand a100:1compression ratio.- Returns:
- a default request decompression policy
-
builder
Acquires a builder for an enabled request decompression policy with custom limits.- Returns:
- a request decompression policy builder
-
isEnabled
-
getMaximumDecompressedBodySizeInBytes
The maximum permitted decompressed body size in bytes, if customized.When empty, the server's
maximumRequestSizeInBytesapplies to the decompressed body.- Returns:
- the maximum decompressed body size, or
Optional.empty()to use the server's request size limit
-
getMaximumCompressionRatio
The maximum permitted expansion ratio between decompressed and compressed body sizes.A request is rejected with
413 Content Too Largeonce its decompressed size exceeds(compressed size × ratio) + 8 KB; the additive allowance keeps legitimately small compressed bodies from tripping the ratio check.- Returns:
- the maximum compression ratio (default
100)
-
toString
-