Module

x/opine/deps.ts>Accepts

Fast, minimalist web framework for Deno ported from ExpressJS.
Go to Latest
class Accepts
import { Accepts } from "https://dotland.deno.dev/x/opine@2.2.0/deps.ts";

Create a new Accepts object for the given headers.

Constructors

new
Accepts(headers: Headers)

Properties

private
headers: Headers
private
negotiator: Negotiator

Methods

charsets(charsets?: string[]): string[] | string | false

Return accepted charsets or best fit based on charsets.

Given Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5 an array sorted by quality is returned:

['utf-8', 'utf-7', 'iso-8859-1']
encodings(encodings?: string[]): string[] | string | false

Return accepted encodings or best fit based on encodings.

Given Accept-Encoding: gzip, deflate an array sorted by quality is returned:

['gzip', 'deflate']
languages(languages?: string[]): string[] | string | false

Return accepted languages or best fit based on langs.

Given Accept-Language: en;q=0.8, es, pt an array sorted by quality is returned:

['es', 'pt', 'en']
types(types?: string[]): string[] | string | false

Check if the given type(s) is acceptable, returning the best match when true, otherwise undefined, in which case you should respond with 406 "Not Acceptable".

The type value may be a single mime type string such as "application/json", the extension name such as "json" or an array ["json", "html", "text/plain"]. When a list or array is given the best match, if any is returned.

Examples:

// Accept: text/html
this.types(['html']);
// => ["html"]

// Accept: text/*, application/json
this.types(['html']);
// => ["html"]
this.types(['text/html']);
// => ["text/html"]
this.types(['json', 'text']);
// => ["json"]
this.types(['application/json']);
// => ["application/json"]

// Accept: text/*, application/json
this.types(['image/png']);
this.types(['png']);
// => []

// Accept: text/*;q=.5, application/json
this.types(['html', 'json']);
// => ["json"]