/** * Framework-agnostic readers for HTTP requests, shared across AppKit * plugins: header and cookie extraction. Works uniformly across * Express, Node `IncomingMessage`, WHATWG `Request` / `Response` / * `Headers`, Hono, and any object that exposes a `headers` field of one * of those shapes. Dependency-free and browser-safe so it can run in * either a server or a client bundle. * * URL path matching lives on `net.urlBuilder` (`pathMatches`). * * @module */ /** * Anything that contains HTTP headers. Accepts: * * - A WHATWG `Headers` instance (fetch / undici / Hono `c.req.raw.headers`). * - A header record (`Record`), * Node / Express style. * - Any object with a `headers` field of one of the above. This covers * Express `req`, Node `IncomingMessage`, WHATWG `Request` / `Response`, * Hono `c.req.raw`, and similar shapes. */ export type HeaderLike = Headers | HeaderRecord | { headers: Headers | HeaderRecord; }; /** * Single header value as exposed by Node `IncomingMessage.headers` and * Express `req.headers` (string for most headers, array for repeated * headers such as `Set-Cookie`). */ type HeaderValueLike = string[] | string | undefined; /** Header bag with case-insensitive keys (Node / Express style). */ type HeaderRecord = Record; /** * Invokes `consumer` once per value for `headerName`, case-insensitive. * * - **Record input:** if the field is an array (e.g. repeated `Set-Cookie`), * `consumer` runs once per array item. * - **`Headers` input:** uses `get(name)` (which spec-joins repeats with * `, `) except for `Set-Cookie`, which uses `getSetCookie()` so each * cookie is delivered separately. * * @example * forEachHeaderValue(req, "x-trace-id", (v) => spans.push(v)); // Express * forEachHeaderValue(c.req.raw, "set-cookie", (v) => log(v)); // Hono * forEachHeaderValue(headersInstance, "cookie", parse); // fetch */ export declare function forEachHeaderValue(input: HeaderLike | null | undefined, headerName: string, consumer: (value: string) => void): void; /** * Parses `Cookie` header values into a name-to-value map (URI-decoded). * * Accepts: * * - A raw `Cookie` string (`"a=1; b=2"`). * - An array of such strings (e.g. multiple `Cookie` headers). * - Any {@link HeaderLike}: a WHATWG `Headers` instance, a header * record, or a request-like object with a `headers` field. * * First occurrence of each cookie name wins; later duplicates are ignored. * * @example * parseCookies("session=abc; theme=dark"); * // { session: "abc", theme: "dark" } * * parseCookies(req); // Express / Node * parseCookies(c.req.raw); // Hono * parseCookies(request); // fetch Request * parseCookies(request.headers); // WHATWG Headers directly */ export declare function parseCookies(input: HeaderLike | HeaderValueLike | null): Record; /** * Build an `Error` describing a failed `fetch` response: status line, * the URL(s) involved (the requested `url` and the final `response.url` * after redirects, de-duplicated), and a truncated snapshot of the * response body. Reads the body defensively - a body that can't be read * is simply omitted. Call only on a non-`ok` response. */ export declare function createFetchError(response: Response, url?: string): Promise; export {};