Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno_koa/test/test_deps.ts>Accepts

A middleware framework for Deno's http serve🦕. Transplanted from Koa with ❤️
Latest
class Accepts
import { Accepts } from "https://deno.land/x/deno_koa@v1.0.4/test/test_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[]

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[]

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[]

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[]

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"]