[]previous and next page

negotiateEncoding

Chooses a content coding from Accept-Encoding: the highest q-value wins, and a tie goes to brotli, then zstd (only where node:zlib has it), then gzip.

Chooses a content coding from Accept-Encoding: the highest q-value wins, and a tie goes to brotli, then zstd (only where node:zlib has it), then gzip. q=0 refuses a coding. The header is bounded (1 KiB, 16 elements); anything beyond is ignored, so it cannot cost CPU.

Import#

ts
import { negotiateEncoding } from "@shadow-js/dusk/node";

Signature#

ts
function negotiateEncoding(header: string | null | undefined): Encoding | undefined

Parameters#

Name Description
header The Accept-Encoding value.

Returns#

The coding to use, or undefined for identity.

Examples#

ts
negotiateEncoding("gzip, deflate, br;q=0.9"); // "gzip" has q=1, br has 0.9 -> "gzip"