Skip to main content

@std/http@0.215.0

latest
Works with
It is unknown whether this package works with Browsers, Deno, Node.js, Cloudflare Workers, Bun
It is unknown whether this package works with Browsers
It is unknown whether this package works with Deno
It is unknown whether this package works with Node.js
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Published2 years ago (0.215.0)
function acceptsEncodings
acceptsEncodings(request: Request): string[]

Returns an array of content encodings accepted by the request, in order of preference. If there are no encoding supplied in the request, then ["*"] is returned, implying any encoding is accepted.

Examples

Example 1

import { acceptsEncodings } from "@std/http/negotiation";

const req = new Request("https://example.com/", {
  headers: { "accept-encoding": "deflate, gzip;q=1.0, *;q=0.5" },
});

acceptsEncodings(req); // ["deflate", "gzip", "*"]

Parameters

Return Type

acceptsEncodings(
request: Request,
...encodings: string[]
): string | undefined

For a given set of content encodings, return the best match accepted in the request. If no content encodings match, then the function returns undefined.

NOTE: You should always supply identity as one of the encodings to ensure that there is a match when the Accept-Encoding header is part of the request.

Examples

Example 1

import { acceptsEncodings } from "@std/http/negotiation";

const req = new Request("https://example.com/", {
  headers: { "accept-encoding": "deflate, gzip;q=1.0, *;q=0.5" },
});

acceptsEncodings(req, "gzip", "identity"); // "gzip"

Parameters

...encodings: string[]

Return Type

string | undefined

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/http

Import symbol

import { acceptsEncodings } from "@std/http/negotiation";
or

Import directly with a jsr specifier

import { acceptsEncodings } from "jsr:@std/http/negotiation";