compress
Negotiates Accept-Encoding and wraps the response stream through the
best-matching compressor (Brotli, gzip, or deflate). Compression is
skipped automatically for small bodies, non-compressible content types,
and no-body status codes.
Pipeline stage: Cross-cutting (place before send)
Import
Section titled “Import”import { compress } from "@centralping/ergo";Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
threshold | number | 1024 | Minimum body size in bytes before compression kicks in |
encodings | string[] | ['br', 'gzip', 'deflate'] | Supported encodings in priority order |
Return Value
Section titled “Return Value”The middleware modifies the response stream in-place (wrapping
res.write and res.end). It does not add to the domain accumulator.
Compression Skipped When
Section titled “Compression Skipped When”- Status code is 204 or 304
Content-Typeis non-compressible (binary, images, etc.)- Body is below
thresholdbytes - No acceptable encoding found in
Accept-Encoding
Error Responses
Section titled “Error Responses”None. Compression is silently skipped when conditions are not met.
import { compose, compress } from "@centralping/ergo";
const pipeline = compose( compress({ threshold: 1024, encodings: ["br", "gzip"] }), (req, res, acc) => ({ response: { body: largePayload }, }),);const router = createRouter({ defaults: { compress: { threshold: 512 }, },});RFC References
Section titled “RFC References”API Reference
Section titled “API Reference”See the auto-generated compress API docs.