UNPKG

@foxify/http

Version:
107 lines 4.13 kB
/** * Copyright (c) 2014-2018, Project contributors. * Copyright (c) 2015-2016, Mark Bradshaw * Copyright (c) 2014, Walmart. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The names of any contributors may not be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import Negotiator from "negotiator"; import type { default as Request, HeadersI } from "../Request"; declare class Accepts { protected headers: HeadersI; protected negotiator: Negotiator; constructor(req: Request); /** * 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"] */ charsets(charsets?: 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"] */ encodings(encodings?: 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"] * * @param {String|Array} languages... * @return {Array|String} * @public */ languages(languages?: 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. * * @example * // Accept: text/html * this.types("html"); * // => "html" * * @example * // 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" * * @example * // Accept: text/*, application/json * this.types("image/png"); * this.types("png"); * // => undefined * * @example * // Accept: text/*;q=.5, application/json * this.types(["html", "json"]); * this.types("html", "json"); * // => "json" */ types(types?: string[]): string[] | string | false; } export default Accepts; //# sourceMappingURL=accepts.d.ts.map