UNPKG

@remix-run/headers

Version:

A toolkit for working with HTTP headers in JavaScript

422 lines 18.8 kB
import { type AcceptInit, Accept } from './accept.ts'; import { type AcceptEncodingInit, AcceptEncoding } from './accept-encoding.ts'; import { type AcceptLanguageInit, AcceptLanguage } from './accept-language.ts'; import { type CacheControlInit, CacheControl } from './cache-control.ts'; import { type ContentDispositionInit, ContentDisposition } from './content-disposition.ts'; import { type ContentTypeInit, ContentType } from './content-type.ts'; import { type CookieInit, Cookie } from './cookie.ts'; import { type HeaderValue } from './header-value.ts'; import { type IfNoneMatchInit, IfNoneMatch } from './if-none-match.ts'; import { type SetCookieInit, SetCookie } from './set-cookie.ts'; type DateInit = number | Date; interface SuperHeadersPropertyInit { /** * The [`Accept`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept) header value. */ accept?: string | AcceptInit; /** * The [`Accept-Encoding`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding) header value. */ acceptEncoding?: string | AcceptEncodingInit; /** * The [`Accept-Language`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language) header value. */ acceptLanguage?: string | AcceptLanguageInit; /** * The [`Accept-Ranges`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Ranges) header value. */ acceptRanges?: string; /** * The [`Age`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age) header value. */ age?: string | number; /** * The [`Cache-Control`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) header value. */ cacheControl?: string | CacheControlInit; /** * The [`Connection`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection) header value. */ connection?: string; /** * The [`Content-Disposition`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) header value. */ contentDisposition?: string | ContentDispositionInit; /** * The [`Content-Encoding`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding) header value. */ contentEncoding?: string | string[]; /** * The [`Content-Language`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language) header value. */ contentLanguage?: string | string[]; /** * The [`Content-Length`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length) header value. */ contentLength?: string | number; /** * The [`Content-Type`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) header value. */ contentType?: string | ContentTypeInit; /** * The [`Cookie`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie) header value. */ cookie?: string | CookieInit; /** * The [`Date`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date) header value. */ date?: string | DateInit; /** * The [`ETag`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag) header value. */ etag?: string; /** * The [`Expires`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires) header value. */ expires?: string | DateInit; /** * The [`Host`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host) header value. */ host?: string; /** * The [`If-Modified-Since`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since) header value. */ ifModifiedSince?: string | DateInit; /** * The [`If-None-Match`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match) header value. */ ifNoneMatch?: string | string[] | IfNoneMatchInit; /** * The [`If-Unmodified-Since`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Unmodified-Since) header value. */ ifUnmodifiedSince?: string | DateInit; /** * The [`Last-Modified`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified) header value. */ lastModified?: string | DateInit; /** * The [`Location`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location) header value. */ location?: string; /** * The [`Referer`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer) header value. */ referer?: string; /** * The [`Set-Cookie`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) header value(s). */ setCookie?: string | (string | SetCookieInit)[]; } export type SuperHeadersInit = Iterable<[string, string]> | (SuperHeadersPropertyInit & Record<string, string | HeaderValue>); /** * An enhanced JavaScript `Headers` interface with type-safe access. * * [API Reference](https://github.com/remix-run/remix/tree/v3/packages/headers) * * [MDN `Headers` Base Class Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers) */ export declare class SuperHeaders extends Headers { #private; constructor(init?: string | SuperHeadersInit | Headers); /** * Appends a new header value to the existing set of values for a header, * or adds the header if it does not already exist. * * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers/append) */ append(name: string, value: string): void; /** * Removes a header. * * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers/delete) */ delete(name: string): void; /** * Returns a string of all the values for a header, or `null` if the header does not exist. * * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers/get) */ get(name: string): string | null; /** * Returns an array of all values associated with the `Set-Cookie` header. This is * useful when building headers for a HTTP response since multiple `Set-Cookie` headers * must be sent on separate lines. * * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers/getSetCookie) */ getSetCookie(): string[]; /** * Returns `true` if the header is present in the list of headers. * * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers/has) */ has(name: string): boolean; /** * Sets a new value for the given header. If the header already exists, the new value * will replace the existing value. * * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers/set) */ set(name: string, value: string): void; /** * Returns an iterator of all header keys (lowercase). * * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers/keys) */ keys(): IterableIterator<string>; /** * Returns an iterator of all header values. * * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers/values) */ values(): IterableIterator<string>; /** * Returns an iterator of all header key/value pairs. * * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers/entries) */ entries(): IterableIterator<[string, string]>; [Symbol.iterator](): IterableIterator<[string, string]>; /** * Invokes the `callback` for each header key/value pair. * * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers/forEach) */ forEach(callback: (value: string, key: string, headers: SuperHeaders) => void, thisArg?: any): void; /** * Returns a string representation of the headers suitable for use in a HTTP message. */ toString(): string; /** * The `Accept` header is used by clients to indicate the media types that are acceptable * in the response. * * [MDN `Accept` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2) */ get accept(): Accept; set accept(value: string | AcceptInit | undefined | null); /** * The `Accept-Encoding` header contains information about the content encodings that the client * is willing to accept in the response. * * [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) */ get acceptEncoding(): AcceptEncoding; set acceptEncoding(value: string | AcceptEncodingInit | undefined | null); /** * The `Accept-Language` header contains information about preferred natural language for the * response. * * [MDN `Accept-Language` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.5) */ get acceptLanguage(): AcceptLanguage; set acceptLanguage(value: string | AcceptLanguageInit | undefined | null); /** * The `Accept-Ranges` header indicates the server's acceptance of range requests. * * [MDN `Accept-Ranges` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Ranges) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7233#section-2.3) */ get acceptRanges(): string | null; set acceptRanges(value: string | undefined | null); /** * The `Age` header contains the time in seconds an object was in a proxy cache. * * [MDN `Age` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Age) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7234#section-5.1) */ get age(): number | null; set age(value: string | number | undefined | null); /** * The `Cache-Control` header contains directives for caching mechanisms in both requests and responses. * * [MDN `Cache-Control` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7234#section-5.2) */ get cacheControl(): CacheControl; set cacheControl(value: string | CacheControlInit | undefined | null); /** * The `Connection` header controls whether the network connection stays open after the current * transaction finishes. * * [MDN `Connection` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Connection) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7230#section-6.1) */ get connection(): string | null; set connection(value: string | undefined | null); /** * The `Content-Disposition` header is a response-type header that describes how the payload is displayed. * * [MDN `Content-Disposition` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition) * * [RFC 6266](https://datatracker.ietf.org/doc/html/rfc6266) */ get contentDisposition(): ContentDisposition; set contentDisposition(value: string | ContentDispositionInit | undefined | null); /** * The `Content-Encoding` header specifies the encoding of the resource. * * Note: If multiple encodings have been used, this value may be a comma-separated list. However, most often this * header will only contain a single value. * * [MDN `Content-Encoding` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding) * * [HTTP/1.1 Specification](https://httpwg.org/specs/rfc9110.html#field.content-encoding) */ get contentEncoding(): string | null; set contentEncoding(value: string | string[] | undefined | null); /** * The `Content-Language` header describes the natural language(s) of the intended audience for the response content. * * Note: If the response content is intended for multiple audiences, this value may be a comma-separated list. However, * most often this header will only contain a single value. * * [MDN `Content-Language` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Language) * * [HTTP/1.1 Specification](https://httpwg.org/specs/rfc9110.html#field.content-language) */ get contentLanguage(): string | null; set contentLanguage(value: string | string[] | undefined | null); /** * The `Content-Length` header indicates the size of the entity-body in bytes. * * [MDN `Content-Length` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Length) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.2) */ get contentLength(): number | null; set contentLength(value: string | number | undefined | null); /** * The `Content-Type` header indicates the media type of the resource. * * [MDN `Content-Type` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-3.1.1.5) */ get contentType(): ContentType; set contentType(value: string | ContentTypeInit | undefined | null); /** * The `Cookie` request header contains stored HTTP cookies previously sent by the server with * the `Set-Cookie` header. * * [MDN `Cookie` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc6265#section-5.4) */ get cookie(): Cookie; set cookie(value: string | CookieInit | undefined | null); /** * The `Date` header contains the date and time at which the message was sent. * * [MDN `Date` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Date) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.1.2) */ get date(): Date | null; set date(value: string | DateInit | undefined | null); /** * The `ETag` header provides a unique identifier for the current version of the resource. * * [MDN `ETag` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7232#section-2.3) */ get etag(): string | null; set etag(value: string | undefined | null); /** * The `Expires` header contains the date/time after which the response is considered stale. * * [MDN `Expires` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7234#section-5.3) */ get expires(): Date | null; set expires(value: string | DateInit | undefined | null); /** * The `Host` header specifies the domain name of the server and (optionally) the TCP port number. * * [MDN `Host` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7230#section-5.4) */ get host(): string | null; set host(value: string | undefined | null); /** * The `If-Modified-Since` header makes a request conditional on the last modification date of the * requested resource. * * [MDN `If-Modified-Since` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7232#section-3.3) */ get ifModifiedSince(): Date | null; set ifModifiedSince(value: string | DateInit | undefined | null); /** * The `If-None-Match` header makes a request conditional on the absence of a matching ETag. * * [MDN `If-None-Match` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7232#section-3.2) */ get ifNoneMatch(): IfNoneMatch; set ifNoneMatch(value: string | string[] | IfNoneMatchInit | undefined | null); /** * The `If-Unmodified-Since` header makes a request conditional on the last modification date of the * requested resource. * * [MDN `If-Unmodified-Since` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Unmodified-Since) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7232#section-3.4) */ get ifUnmodifiedSince(): Date | null; set ifUnmodifiedSince(value: string | DateInit | undefined | null); /** * The `Last-Modified` header contains the date and time at which the resource was last modified. * * [MDN `Last-Modified` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Last-Modified) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7232#section-2.2) */ get lastModified(): Date | null; set lastModified(value: string | DateInit | undefined | null); /** * The `Location` header indicates the URL to redirect to. * * [MDN `Location` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1.2) */ get location(): string | null; set location(value: string | undefined | null); /** * The `Referer` header contains the address of the previous web page from which a link to the * currently requested page was followed. * * [MDN `Referer` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc7231#section-5.5.2) */ get referer(): string | null; set referer(value: string | undefined | null); /** * The `Set-Cookie` header is used to send cookies from the server to the user agent. * * [MDN `Set-Cookie` Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie) * * [HTTP/1.1 Specification](https://datatracker.ietf.org/doc/html/rfc6265#section-4.1) */ get setCookie(): SetCookie[]; set setCookie(value: (string | SetCookieInit)[] | string | SetCookieInit | undefined | null); } export {}; //# sourceMappingURL=super-headers.d.ts.map