ring.middleware.content-encoding

Middleware for adding Content-Encoding to a response.

brotli-encoder

(brotli-encoder)(brotli-encoder options)

Returns a function that adds Brotli compression to an OutputStream. Accepts the following options:

  • :quality - compression quality
  • :window - log2(LZ window size)

content-encoding-response

(content-encoding-response response request)(content-encoding-response response request options)

Add Content-Encoding to a response, based on the types included in the Accept-Encoding header on the request. See wrap-content-encoding for information on the supported options.

default-encoder-minimums

The minimum size in bytes at which to apply the compression. Bodies that are too small typically don’t benefit from compression.

default-encoder-weights

Weightings for which encoder to favor when the client has no preference. Higher values win out over lower ones.

default-encoders

A map of encoder names to their respective default functions.

default-media-types

A set of default media types that will get content encoding. Media types that already have compression (such as images) should not be included in this set.

default-status-codes

A set of default status codes that will get content encoding.

deflate-encoder

(deflate-encoder)(deflate-encoder options)

Returns a function that adds DEFLATE compression to an OutputStream. Accepts the following options:

  • :level - the compression level

gzip-encoder

(gzip-encoder)(gzip-encoder options)

Returns a function that adds GZip compression to an OutputStream. Accepts the following options:

  • :level - the compression level

wrap-content-encoding

(wrap-content-encoding handler)(wrap-content-encoding handler options)

Wrap a Ring handler to apply appropriate Content-Encoding to a response, based on the types included in the Accept-Encoding header on the request. Accepts the following options:

  • :encoders - a map of encoder names to functions that add encoding to OutputStreams.
  • :encoder-weights - a map of encoder names to numerial weights. When the client doesn’t favor an encoder, the highest weighted encoder is used.
  • :encoder-minimums - a map of encoder names to the minimum size in bytes of the body (as set by the Content-Length header) at which that encoder is applied
  • :media-types - a set of media types that are allowed to have content encoding
  • :status-codes - a set of HTTP response status codes that are allowed to have content encoding

zstandard-encoder

(zstandard-encoder)(zstandard-encoder options)

Returns a function that adds ZStandard compression to an OutputStream. Accepts the following basic options:

  • :level - the compression level

And the following advanced options:

  • :chain-log - log2(multi-probe search table size)
  • :hash-log - log2(initial probe table size)
  • :job-size - size of compression job when workers > 1
  • :long - enable long distance matching
  • :min-match - min match size for long distance matcher
  • :overlap-log - overlap size as fraction of window size
  • :search-log - log2(number search attempts)
  • :strategy - see ZSTD_strategy enum definition
  • :target-length - depends on strategy
  • :window-log - log2(max allowed back-reference distance)
  • :workers - number of worker threads