acceptsEncodings
import { acceptsEncodings } from "jsr:@ende/http";function
function acceptsEncodings(request: Pick<Request, "headers">): 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.
request: Pick<Request, "headers">The request to get the acceptable content encodings for.
Returns
An array of content encodings this request accepts.
Example: Usage
import { acceptsEncodings } from "@ende/http/negotiation";
import { assertEquals } from "@ende/assert";
const request = new Request("https://example.com/", {
headers: { "accept-encoding": "deflate, gzip;q=1.0, *;q=0.5" },
});
assertEquals(acceptsEncodings(request), ["deflate", "gzip", "*"]);
function
function acceptsEncodings<T extends string = string>(request: Pick<Request, "headers">, ...encodings: T[]): T | undefinedFor 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.
request: Pick<Request, "headers">The request to get the acceptable content encodings for.
...encodings: T[]An array of encodings to find the best matching one from.
Returns
The best matching encoding, if any match.
Example: Usage
import { acceptsEncodings } from "@ende/http/negotiation";
import { assertEquals } from "@ende/assert";
const request = new Request("https://example.com/", {
headers: { "accept-encoding": "deflate, gzip;q=1.0, *;q=0.5" },
});
assertEquals(acceptsEncodings(request, "gzip", "identity"), "gzip");
function
function acceptsEncodings(request: Pick<Request, "headers">, ...encodings: string[]): string | string[] | undefined