property

BunFetchRequestInit.compress

compress?: boolean | 'deflate' | 'gzip' | 'br' | 'zstd' | { encoding: 'deflate' | 'gzip' | 'br' | 'zstd'; level: number }

Automatically compress the request body before sending and set the Content-Encoding request header accordingly.

  • true is equivalent to "gzip".
  • A string selects the encoding with its default level.
  • An object selects the encoding and an explicit compression level.

Only buffered bodies (string, ArrayBuffer/TypedArray, Blob) are compressed; ReadableStream bodies are sent as-is. If the request already has a Content-Encoding header, the body is left unchanged. Not part of the Fetch API specification.

await fetch("https://example.com/upload", {
  method: "POST",
  body: JSON.stringify(bigPayload),
  compress: "gzip",
});