import { RequestCookies, ResponseCookies } from '@edge-runtime/cookies'; export { RequestCookies, ResponseCookies, parseCookie, parseSetCookie, stringifyCookie } from '@edge-runtime/cookies'; import { sha1 } from './crypto.js'; import { userAgentFromString } from '@edge-runtime/user-agent'; export { isBot, userAgentFromString } from '@edge-runtime/user-agent'; type AcceptHeader = 'Accept' | 'Accept-Charset' | 'Accept-Encoding' | 'Accept-Language' | 'Accept-Patch' | 'Accept-Post' | 'Accept-Ranges'; interface Accept { type: string; params: Record; quality: number; } interface acceptsConfig { header: AcceptHeader; supports: string[]; default: string; } interface acceptsOptions extends acceptsConfig { match?: (accepts: Accept[], config: acceptsConfig) => string; } declare const parseAccept: (acceptHeader: string) => { type: string; params: {}; quality: number; }[]; declare const defaultMatchAccept: (accepts: Accept[], config: acceptsConfig) => string; /** * Match the accept header with the given options. * @example * ```ts * const lang = matchAccepts(req, { * header: 'Accept-Language', * supports: ['en', 'zh'], * default: 'en', * }); */ declare const matchAccepts: (headers: Headers, options: acceptsOptions) => string; interface ResponseCacheControl { /** * The `immutable` response directive. * It indicates that the response will not be updated * while it's fresh. */ immutable?: boolean; /** * The `max-age=N` response directive. * It indicates that the response remains fresh until N seconds * after the response is generated. */ maxAge?: number; /** * The `must-revalidate` response directive. * It indicates that the response can be stored in caches * and can be reused while fresh. If the response becomes stale, * it must be validated with the origin server before reuse. */ mustRevalidate?: boolean; /** * The `must-understand` response directive. * It indicates that a cache should store the response only * if it understands the requirements for caching based on status code. */ mustUnderstand?: boolean; /** * The `no-cache` response directive. * It indicates that the response can be stored in caches, * but the response must be validated with the origin server * before each reuse, even when the cache is disconnected from the origin server. */ noCache?: boolean; /** * The `no-store` response directive. * It indicates that any caches of any kind (private or shared) * should not store this response. */ noStore?: boolean; /** * `no-transform` directive. * It indicates that any intermediary (regardless of whether * it implements a cache) shouldn't transform the response contents. */ noTransform?: boolean; /** * The `proxy-revalidate` response directive. * It is the equivalent of `must-revalidate`, * but specifically for shared caches only. */ proxyRevalidate?: boolean; /** * Configures the resource to be public. * It means it can be shared even if * the request carries an authentication header. */ public?: boolean; /** * The `s-maxage` response directive. * It indicates how long the response remains fresh in a shared cache. * The `s-maxage` directive is ignored by private caches, * and overrides the value specified by the `max-age` directive * or the Expires header for shared caches, if they are present. */ sharedMaxAge?: number; /** * The `stale-if-error` response directive. * It indicates that the cache can reuse a stale response * when an upstream server generates an error, * or when the error is generated locally. * Here, an error is considered any response with a status code of 500, 502, 503, or 504. */ staleIfError?: number; /** * The `stale-while-revalidate` response directive. * It indicates that the cache could reuse a stale response * while it revalidates it to a cache. */ staleWhileRevalidate?: number; } interface RequestCacheControl { /** * The `max-age=N` request directive. * It indicates that the client allows a stored response * that is generated on the origin server within N seconds. * Here, N may be any non-negative integer (including 0). */ maxAge?: number; /** * The `max-stale=N` request directive. * It indicates that the client allows a stored response * that is stale within N seconds. */ maxStale?: number; /** * The `min-fresh=N` request directive. * It indicates that the client allows a stored response * that is fresh for at least N seconds. */ minFresh?: number; /** * The `no-cache` request directive. * It asks caches to validate the response with the origin server before reuse. */ noCache?: boolean; /** * The `no-store` request directive. * It allows a client to request that caches refrain from storing * the request and corresponding response. * This is even if the origin server's response could be stored. */ noStore?: boolean; /** * Same meaning that `no-transform` has for a response, * but for a request instead. */ noTransform?: boolean; /** * The client indicates that an already-cached response should be returned. * If a cache has a stored response, even a stale one, it will be returned. * If no cached response is available, a 504 Gateway Timeout response will be returned. */ onlyIfCached?: boolean; } declare function stringifyResponseCacheControl(cacheControl: ResponseCacheControl): string; declare function stringifyRequestCacheControl(cacheControl: RequestCacheControl): string; /** * Append `cache-control` headers. */ declare function cacheControl(headers: Headers, cacheControl: string | string[], replace?: boolean): void; /** * Append `cache-control` headers to a response. */ declare function responseCacheControl(headers: Headers, cacheControl: ResponseCacheControl, replace?: boolean): void; /** * Append `cache-control` headers to a request. */ declare function requestCacheControl(headers: Headers, cacheControl: RequestCacheControl, replace?: boolean): void; /** Read HTTP incoming request cookies. */ declare function cookies(): RequestCookies; /** Write HTTP outgoing response cookies. */ declare function cookies(headers: Headers): ResponseCookies; declare function etag(entity: Parameters[0], options?: { weak?: boolean; }): Promise; /*! * fresh * https://github.com/jshttp/fresh * Copyright(c) 2012 TJ Holowaychuk * Copyright(c) 2016-2017 Douglas Christopher Wilson * MIT Licensed */ /** * Check freshness of the response using request and response headers. */ declare function fresh(reqHeaders: Headers, resHeaders: Headers): boolean; /** Read HTTP incoming request headers. */ declare function headers(): Headers; /** * Determine the device type based on the User-Agent header. * - Mobile: `(?:phone|windows\s+phone|ipod|blackberry|(?:android|bb\d+|meego|silk|googlebot) .+? mobile|palm|windows\s+ce|opera\ mini|avantgo|mobilesafari|docomo|KAIOS)` * - Tablet: `(?:ipad|playbook|(?:android|bb\d+|meego|silk)(?! .+? mobile))` * - Desktop: Everything else not matched above. * @see https://developers.cloudflare.com/cache/how-to/edge-browser-cache-ttl/create-page-rules/#cache-by-device-type-enterprise-only * @deprecated Use `userAgent` instead. */ declare function deviceType(headers: Headers): "mobile" | "tablet" | "desktop"; declare function userAgent( /** @deprecated */ request: Request): ReturnType; /** Read HTTP incoming request user agent. */ declare function userAgent(headers?: Headers): ReturnType; /*! * vary * https://github.com/jshttp/vary/tree/master * Copyright(c) 2014-2017 Douglas Christopher Wilson * MIT Licensed */ declare function vary(headers: Headers, field: string | string[]): void; export { type Accept, type AcceptHeader, type RequestCacheControl, type ResponseCacheControl, type acceptsConfig, type acceptsOptions, cacheControl, cookies, defaultMatchAccept, deviceType, etag, fresh, headers, matchAccepts, parseAccept, requestCacheControl, responseCacheControl, stringifyRequestCacheControl, stringifyResponseCacheControl, userAgent, vary };