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 Details

    • disabledInstance

      Acquires a policy that disables response gzip.
      Returns:
      a disabled response gzip policy
    • fromDefaultsWithMinimumBodySizeInBytes

      Acquires a policy that gzips common text-like response media types when the finalized body is at least minimumBodySizeInBytes.

      The default media-type set includes text/*, application/json, application/*+json, application/xml, application/*+xml, application/javascript, application/graphql, application/x-www-form-urlencoded, and image/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 true permits gzip; returning false writes the response unchanged.

      Parameters:
      request - the request being handled
      response - the finalized response being written
      Returns:
      true to gzip the response, or false to write it unchanged