Function acceptsEncodings
- accepts
Encodings (request): string[] Parameters
- request: Pick<Request, "headers">
The request to get the acceptable content encodings for.
Returns string[]
An array of content encodings this request accepts.
Example: Usage
import { acceptsEncodings } from "@std/http/negotiation";
import { assertEquals } from "@std/assert";
const request = new Request("https://example.com/", {
headers: { "accept-encoding": "deflate, gzip;q=1.0, *;q=0.5" },
});
assertEquals(acceptsEncodings(request), ["deflate", "gzip", "*"]);- request: Pick<Request, "headers">
- accepts
Encodings (request, ...encodings): 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
identityas one of the encodings to ensure that there is a match when theAccept-Encodingheader is part of the request.Parameters
- request: Pick<Request, "headers">
The request to get the acceptable content encodings for.
Rest...encodings: string[]An array of encodings to find the best matching one from.
Returns string | undefined
The best matching encoding, if any match.
Example: Usage
import { acceptsEncodings } from "@std/http/negotiation";
import { assertEquals } from "@std/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");- request: Pick<Request, "headers">
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.