/** * Navidrome MCP Server - Web UI HTTP Helpers * Copyright (C) 2025 * SPDX-License-Identifier: AGPL-3.0-or-later */ import type { IncomingMessage, ServerResponse } from 'node:http'; import type { z } from 'zod'; export declare const SSE_END_FLUSH_GRACE_MS = 2000; /** Set before routing, since `writeHead` merges these into every response a handler writes. */ export declare function setSecurityHeaders(res: ServerResponse): void; export declare const CROSS_ORIGIN_REFUSAL = "Request refused, since it came from another site."; export declare const ORIGIN_MISMATCH_REFUSAL = "Request refused, since it came from another site. A reverse proxy in front of the player must keep the browser's Host header and scheme."; /** * The browser computes `Sec-Fetch-Site` from the page's real origin, so a reverse proxy that rewrites * Host or terminates TLS cannot break it, and it decides alone when present. The Origin compare covers * browsers that omit it. A client that sends neither is not a browser, so no page can make it act with * the user's access. An opaque origin sends `Origin: null`, which fails the URL parse. * Returns null for a request that may proceed. */ export declare function crossOriginRefusal(req: IncomingMessage): string | null; export declare function writeJson(res: ServerResponse, status: number, body: unknown): void; export declare function writeError(res: ServerResponse, status: number, message: string): void; /** The target can depend on the session, so no browser or proxy may reuse the answer. */ export declare function writeRedirect(res: ServerResponse, location: string): void; /** * `refused` names what was refused, such as "login attempts" or "searches", in the message the page shows. * `retryAfterMs` lets the guest page send a refused add again by itself. */ export declare function writeTooManyRequests(res: ServerResponse, waitMs: number, refused: string): void; /** The retry directive goes first, so the browser learns it even if the stream drops at once. */ export declare function openSseStream(res: ServerResponse, retryMs: number): void; /** * Ends the stream with a last event instead of destroying it, so the frames queued before the event * still flush. A peer that never reads them is destroyed after `SSE_END_FLUSH_GRACE_MS`. */ export declare function endSseStream(res: ServerResponse, event: string, data: unknown): void; export declare function isJsonContentType(contentType: string | undefined): boolean; export declare function runAction(res: ServerResponse, action: () => Promise): Promise; /** An empty body resolves to null, so the caller can tell a missing body from `{}`. */ export declare function readJsonBody(req: IncomingMessage, maxBytes?: number): Promise; /** * Invalid input answers 400 here, because runAction maps every thrown error to 500, the impls' own * ZodErrors included. Resolves to null once the 400 response is written. */ export declare function readValidBody(req: IncomingMessage, res: ServerResponse, schema: z.ZodType): Promise; //# sourceMappingURL=http-helpers.d.ts.map