/** * The version of the HTTP-over-`MessagePort` protocol this package speaks, * sent in every hand-shake that sets up a link. Version 1 was this package's * own `handleStreams` / `sendStream` (no backpressure); version 2 is * webrun-rpc's `connect` / `serve` over `overPipe` with webrun-http-streams' * `fetchOverDuplex` / `serveFetchOverDuplex`: one port per link, calls * multiplexed on it, each call a stream with a one-chunk window in both * directions, and cancellation that reaches the handler. */ export declare const HTTP_LINK_PROTOCOL = "webrun-http-link/2"; export interface HttpLinkOptions { /** * Per-stream inactivity timeout in ms (webrun-rpc's): a stream with no chunk * in either direction for that long fails. Unset — the default — means * none: a slow consumer is throttled, never failed. */ streamTimeout?: number; } /** The calling end of a link: sends requests, gets responses. */ export interface HttpLink { /** Sends `request` and resolves with the response, whose body streams. */ send(request: Request): Promise; /** * Requests whose response has not finished yet: still waiting for the head, * or with a body still streaming. */ readonly inflight: number; /** Resolves when `inflight` falls to 0. */ whenIdle(): Promise; /** * Closes the link. Requests in flight fail with `reason` (default: the link * was closed) instead of hanging. */ close(reason?: Error): Promise; readonly closed: boolean; } /** * Why a request failed when its link went away under it: the far side (the * handler, or the ServiceWorker) was lost. The request may or may not have * been applied. */ export declare class LinkLostError extends Error { constructor(message?: string); } /** Opens the calling end of a link on `port` (one port per link). */ export declare function connectHttpLink(port: MessagePort, { streamTimeout }?: HttpLinkOptions): Promise; /** * Serves `handler` on the answering end of a link. Resolves with a teardown * that abandons the requests still running (their handlers see the * cancellation) and releases the port. */ export declare function serveHttpLink(port: MessagePort, handler: (request: Request) => Response | Promise, { streamTimeout }?: HttpLinkOptions): Promise<() => Promise>; /** * Wraps a `send` so the link knows its requests in flight (for draining and * load-based routing) and can fail them all at once when it is closed. */ export declare function trackedLink(send: (request: Request) => Promise, release: () => Promise | void): HttpLink; //# sourceMappingURL=http-link.d.ts.map