/** * Fail-closed host-binding helpers shared by HTTP-serving adapters and * operator surfaces. Single-sourcing * {@link isLoopbackHost} and {@link assertSafeBind} closes the drift where the * loopback predicate had been re-implemented (weaker) in several places and the * safe-bind guard was missing entirely in others. */ import type { Server, ServerResponse } from "node:http"; import { type AddressInfo } from "node:net"; /** * True only when the host is an exact loopback literal (or the exact conventional * `localhost` name). Hostname prefixes such as `127.attacker.example` are never * treated as loopback. Bracketed IPv6 and IPv4-mapped IPv6 literals are * normalized before classification. */ export declare function isLoopbackHost(host: string): boolean; /** Remove URL-only brackets from an IPv6 bind host. Mismatched brackets remain invalid. */ export declare function normalizeHostForBind(host: string): string; /** True for the IPv4 and IPv6 unspecified addresses used to bind all interfaces. */ export declare function isWildcardHost(host: string): boolean; /** Wrap a bare IPv6 host in brackets so it is safe to embed in a URL. */ export declare function hostForUrl(host: string): string; /** * Refuse to bind a non-loopback host unless explicitly allowed. The caller * supplies the typed error so each adapter keeps its own error code/message. */ export declare function assertSafeBind(host: string, allowNonLoopback: boolean, onUnsafe: (host: string) => Error): void; export interface ListenErrorFactories { /** Build the error raised when the underlying server emits a listen error. */ readonly listenFailed: (reason: string) => Error; /** Build the error raised when no TCP address is available after listen. */ readonly noAddress: () => Error; } /** Promisified `server.listen` that resolves with the bound TCP address. */ export declare function listen(server: Server, port: number, host: string, errors: ListenErrorFactories): Promise; /** Promisified `server.close`. */ export declare function close(server: Server): Promise; /** * Close an HTTP server without letting keep-alive or stuck request sockets make * adapter shutdown unbounded. Active sockets get one grace period before they * are force-closed, followed by one final bounded wait for Node's callback. */ export declare function closeServerBounded(server: Server, forceCloseAfterMs?: number): Promise; export interface BoundedHttpResponseWriterOptions { /** Total UTF-8 bytes callers may queue while the socket is backpressured. */ readonly maxPendingBytes?: number; /** Maximum time a single write may wait for the response's `drain` event. */ readonly drainTimeoutMs?: number; /** Called once when the writer becomes unusable so the owning request can abort. */ readonly onFailure?: (error: Error) => void; } /** * Serialize response writes and honor Node's writable backpressure signal. * This keeps fast model streams from growing the process heap behind a slow or * disconnected HTTP client. */ export declare class BoundedHttpResponseWriter { private readonly response; private readonly maxPendingBytes; private readonly drainTimeoutMs; private readonly onFailure; private pendingBytes; private tail; private failure; constructor(response: ServerResponse, options?: BoundedHttpResponseWriterOptions); write(frame: string): Promise; private writeFrame; private fail; } //# sourceMappingURL=host-safety.d.ts.map