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
Properties
Methods
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']
Return accepted encodings or best fit based on encodings
.
Given Accept-Encoding: gzip, deflate
an array sorted by quality is returned:
['gzip', 'deflate']
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']
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"]