@remix-run/headers
Version:
A toolkit for working with HTTP headers in JavaScript
75 lines • 2.92 kB
TypeScript
import { type HeaderValue } from './header-value.ts';
export type AcceptEncodingInit = Iterable<string | [string, number]> | Record<string, number>;
/**
* The value of a `Accept-Encoding` HTTP header.
*
* [MDN `Accept-Encoding` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding)
*
* [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.4)
*/
export declare class AcceptEncoding implements HeaderValue, Iterable<[string, number]> {
#private;
constructor(init?: string | AcceptEncodingInit);
/**
* An array of all encodings in the header.
*/
get encodings(): string[];
/**
* An array of all weights (q values) in the header.
*/
get weights(): number[];
/**
* The number of encodings in the header.
*/
get size(): number;
/**
* Returns `true` if the header matches the given encoding (i.e. it is "acceptable").
* @param encoding The encoding to check.
* @returns `true` if the encoding is acceptable, `false` otherwise.
*/
accepts(encoding: string): boolean;
/**
* Gets the weight an encoding. Performs wildcard matching so `*` matches all encodings.
* @param encoding The encoding to get.
* @returns The weight of the encoding, or `0` if it is not in the header.
*/
getWeight(encoding: string): number;
/**
* Returns the most preferred encoding from the given list of encodings.
* @param encodings The encodings to choose from.
* @returns The most preferred encoding or `null` if none match.
*/
getPreferred(encodings: string[]): string | null;
/**
* Gets the weight of an encoding. If it is not in the header verbatim, this returns `null`.
* @param encoding The encoding to get.
* @returns The weight of the encoding, or `null` if it is not in the header.
*/
get(encoding: string): number | null;
/**
* Sets an encoding with the given weight.
* @param encoding The encoding to set.
* @param weight The weight of the encoding. Defaults to 1.
*/
set(encoding: string, weight?: number): void;
/**
* Removes the given encoding from the header.
* @param encoding The encoding to remove.
*/
delete(encoding: string): void;
/**
* Checks if the header contains a given encoding.
* @param encoding The encoding to check.
* @returns `true` if the encoding is in the header, `false` otherwise.
*/
has(encoding: string): boolean;
/**
* Removes all encodings from the header.
*/
clear(): void;
entries(): IterableIterator<[string, number]>;
[Symbol.iterator](): IterableIterator<[string, number]>;
forEach(callback: (encoding: string, weight: number, header: AcceptEncoding) => void, thisArg?: any): void;
toString(): string;
}
//# sourceMappingURL=accept-encoding.d.ts.map