import type { FetchLike } from "../handlers/HandlerRegistration.js"; import type { InterceptedRequest } from "./InterceptedRequest.js"; /** What came back from the upstream: the status, the headers a client may see, the bytes. */ export interface UpstreamResult { readonly status: number; readonly headers: readonly (readonly [string, string])[]; readonly body: Buffer; } /** Thrown when the upstream's response body is longer than the gateway relays. */ export declare class UpstreamResponseTooLarge extends Error { constructor(); } export interface UpstreamOptions { readonly url: string; readonly timeoutMs: number; readonly maxResponseBytes: number; readonly fetch: FetchLike; /** Releases what the transport holds open, such as a guarded egress's sockets. */ readonly close?: () => void; /** Relay every cookie host-only, whatever `Domain` the upstream named (a hosted gateway). */ readonly hostOnlyCookies?: boolean; /** Relay every response under a sandboxing content security policy (a hosted gateway). */ readonly sandboxed?: boolean; /** * The credential the gateway presents in place of its caller: the header, * lower-case, and its value, read at each request so a rotation applies at * once. A caller's own value of that header is never forwarded. */ readonly credential?: { readonly header: string; readonly value: () => string; }; /** * The gateway's own token, sent as `agentsafe-gateway-token` so the * upstream can tell the request came through this gateway; read at each * request, like the credential. A caller's value of it is never forwarded, * with or without one. */ readonly gatewayToken?: () => string; } /** * The policy a hosted gateway adds to every relayed response. A browser * renders the response as a unique, opaque origin: no script runs, so a page * one tenant's upstream serves cannot set a cookie for the shared domain * from script (which no `Set-Cookie` rewrite would see), and nothing it * renders is same-origin with its own host. It is added beside any policy the * upstream sent, and a browser enforces every policy it is given, so the * upstream's own can only narrow it further. */ export declare const SANDBOX_POLICY = "sandbox"; /** * A `Set-Cookie` value without its `Domain` attribute, so the client keeps * the cookie for the exact host it came from. Behind a hosted gateway every * tenant is a sibling host under one domain; a cookie one tenant's upstream * set for the parent would otherwise be sent to every other tenant. The * name and value are the first segment and are never touched, whatever they * contain. */ export declare function hostOnlyCookie(value: string): string; /** * The one way the gateway reaches the upstream. It rebuilds the request * from what it is given: the upstream origin from the configuration, the * path and query from the caller, the client's headers minus the ones that * belong to a hop, the body bytes verbatim. Redirects are relayed, never * followed, so the client, and not this process, decides where to go next. */ export declare class Upstream { private readonly options; private readonly origin; constructor(options: UpstreamOptions); get url(): string; get timeoutMs(): number; /** Whether a value can be sent as one header: visible characters, spaces and tabs, nothing else. */ static isHeaderValue(value: string): boolean; /** The upstream URL for a path and query, under the configured base path. */ target(path: string, search: string): string; /** The headers the upstream receives for a client's request, plus what the gateway adds. */ headersFor(request: InterceptedRequest, extra?: Readonly>): Record; /** * The headers of a read the gateway makes on its own behalf, of the target * a write names: none of any caller's, only what the gateway presents as * itself, its upstream credential and its gateway token, when it holds them. */ ownHeaders(): Record; /** The headers, with the gateway's credential and token set over whatever they held. */ private identified; /** * Sends one request and reads the whole answer, bounded. A transport * failure throws; the caller decides what a failure after dispatch means. */ send(method: string, path: string, search: string, headers: Readonly>, body: Buffer, signal: AbortSignal): Promise; /** The whole body, or a refusal once it passes the bound; never a partial relay. */ private static read; close(): void; /** The signal for one send: the configured ceiling, or a tighter budget the caller holds. */ signal(budgetMs?: number): AbortSignal; } //# sourceMappingURL=Upstream.d.ts.map