Interface ResponseGzipPolicy
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Policy used by the standard HTTP server to decide whether an eligible response should be gzipped.
Soklet invokes this policy only after its own HTTP protocol checks pass. For example,
Accept-Encoding must permit gzip, and Soklet will skip streaming, file,
range, already-encoded, transfer-encoded, bodyless, and otherwise ineligible responses.
Implementations must be thread-safe; the standard HTTP server may invoke the policy concurrently
from request-handling threads.
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionstatic @NonNull ResponseGzipPolicyAcquires a policy that disables response gzip.static @NonNull ResponseGzipPolicyfromDefaultsWithMinimumBodySizeInBytes(@NonNull Integer minimumBodySizeInBytes) Acquires a policy that gzips common text-like response media types when the finalized body is at leastminimumBodySizeInBytes.shouldGzip(@NonNull Request request, @NonNull MarshaledResponse response) Decides whether an eligible response should be gzipped.
-
Method Details
-
disabledInstance
Acquires a policy that disables response gzip.- Returns:
- a disabled response gzip policy
-
fromDefaultsWithMinimumBodySizeInBytes
static @NonNull ResponseGzipPolicy fromDefaultsWithMinimumBodySizeInBytes(@NonNull Integer minimumBodySizeInBytes) Acquires a policy that gzips common text-like response media types when the finalized body is at leastminimumBodySizeInBytes.The default media-type set includes
text/*,application/json,application/*+json,application/xml,application/*+xml,application/javascript,application/graphql,application/x-www-form-urlencoded, andimage/svg+xml.- Parameters:
minimumBodySizeInBytes- the minimum finalized body size to gzip- Returns:
- a default response gzip policy
-
shouldGzip
Decides whether an eligible response should be gzipped.Returning
truepermits gzip; returningfalsewrites the response unchanged.- Parameters:
request- the request being handledresponse- the finalized response being written- Returns:
trueto gzip the response, orfalseto write it unchanged
-