CompressOptions
Options of response compression.
Options of response compression.
Import#
ts
import type { CompressOptions } from "@shadow-js/dusk/node";
Signature#
ts
interface CompressOptions {
/** Smallest response worth compressing, in bytes (when the length is known). Default 1024. */
readonly minBytes?: number;
/** Compression level, 1 to 9, for gzip and zstd. `gzipLevel` overrides it for gzip. Default: gzip 6, zstd 3. */
readonly level?: number;
/** Brotli quality, 0 to 5 (higher is slower; dynamic responses stay at or below 5). Default 4. */
readonly brotliQuality?: number;
/** gzip level, 1 to 9. Default `level`, or 6. */
readonly gzipLevel?: number;
/** Most compressions running at once; further responses are sent uncompressed. Default 256. */
readonly maxConcurrent?: number;
/**
* The content types worth compressing. A string is a media type (`"application/x-custom"`) or a family
* (`"image/*"`), compared without parameters and ignoring case; a regular expression is tested against that
* same media type. The list replaces the default one (text, JSON, JavaScript, XML, SVG, WebAssembly).
* `text/event-stream` is never compressed.
*/
readonly types?: readonly (string | RegExp)[];
/**
* Asked once per response that would be compressed; `true` allows it, anything else (including a thrown error or a
* promise) skips compression. Use it to skip responses that reflect a secret next to attacker-controlled text, which
* compression can leak (BREACH). It must answer synchronously.
*/
readonly filter?: (request: Request, response: Response) => boolean;
}
Members#
| Name | Type | Description |
|---|---|---|
minBytes? |
readonly minBytes?: number |
Smallest response worth compressing, in bytes (when the length is known). Default 1024. |
level? |
readonly level?: number |
Compression level, 1 to 9, for gzip and zstd. gzipLevel overrides it for gzip. Default: gzip 6, zstd 3. |
brotliQuality? |
readonly brotliQuality?: number |
Brotli quality, 0 to 5 (higher is slower; dynamic responses stay at or below 5). Default 4. |
gzipLevel? |
readonly gzipLevel?: number |
gzip level, 1 to 9. Default level, or 6. |
maxConcurrent? |
readonly maxConcurrent?: number |
Most compressions running at once; further responses are sent uncompressed. Default 256. |
types? |
readonly types?: readonly (string | RegExp)[] |
The content types worth compressing. A string is a media type ("application/x-custom") or a family ("image/*"), compared without parameters and ignoring case; a regular expression is tested against that same media type. The list replaces the default one (text, JSON, JavaScript, XML, SVG, WebAssembly). text/event-stream is never compressed. |
filter? |
readonly filter?: (request: Request, response: Response) => boolean |
Asked once per response that would be compressed; true allows it, anything else (including a thrown error or a promise) skips compression. Use it to skip responses that reflect a secret next to attacker-controlled text, which compression can leak (BREACH). It must answer synchronously. |