Interface ResponseCompressionCodec


A response-compression implementation and its HTTP content coding.

Soklet supplies gzipInstance() using the JDK's gzip implementation without runtime dependencies. Applications can supply other codecs, including codecs backed by optional external libraries, without adding those libraries to Soklet itself. A codec is selected by a ResponseCompressionPlan; it does not decide request eligibility, negotiate with a client, or write HTTP headers.

Implementations must be thread-safe. Soklet can reuse one codec concurrently for many responses, and does not synchronize access to it.

Author:
Mark Allen
  • Method Details

    • gzipInstance

      Acquires the shared built-in gzip codec.

      The codec uses the JDK's default gzip compression settings and does not cache results.

      Returns:
      a thread-safe gzip codec
    • getContentEncoding

      The single HTTP content coding produced by this codec, such as gzip or br.

      Return a nonempty ASCII HTTP token without whitespace, parameters, or a coding chain. The reserved values identity and * are not compression codecs. A plan validates this value and snapshots its lowercase form at construction; the codec must continue to produce that coding for the lifetime of every plan using it.

      Returns:
      the non-null content coding
    • compress

      byte @NonNull [] compress(@NonNull ByteBuffer uncompressedBody)
      Compresses the bytes between the supplied buffer's position and limit.

      Soklet supplies a read-only buffer view confined to this invocation. An implementation may advance that view's position but must not retain the view, access it after returning, or mutate the underlying response bytes. Compression must complete synchronously on the invoking request-handling thread.

      Return a non-null complete encoding of exactly the supplied bytes, using this codec's content coding. The returned array is not defensively copied. Neither the codec nor any caller may mutate it while a response is writing it or a cache retains it for reuse. A null result or an exception is a response-processing failure; Soklet does not silently send partially encoded or uncompressed bytes.

      Parameters:
      uncompressedBody - the read-only view of the finalized uncompressed body
      Returns:
      the non-null compressed bytes