import { withResponseObserver } from "@nifrajs/core/response-observer" import type { Middleware } from "@nifrajs/core/server" export interface PoweredByOptions { /** Header name. Default `"x-powered-by"`. */ readonly header?: string /** Header value. Default `"Nifra"`. */ readonly value?: string /** Do not overwrite an existing header by default. */ readonly respectExisting?: boolean } /** * Opt-in `X-Powered-By` style header. Nifra does not emit this by default; use it only when you want a * public framework/product marker. */ export function poweredBy(options: PoweredByOptions = {}): Middleware { const header = options.header ?? "x-powered-by" const value = options.value ?? "Nifra" const respectExisting = options.respectExisting !== false if (header.trim() === "") throw new Error("poweredBy: header is empty") if (/[\r\n]/.test(value)) throw new Error("poweredBy: value contains a newline") // Respecting an existing value IS the static tier's contract (declared headers are defaults), so // the default configuration declares the header instead of writing it per response and leaves the // app on its fused/native lanes. Overwriting is a decision about the response, so it stays a hook. if (respectExisting) { return { name: "powered-by", responseHeaders: { [header]: value } } } return withResponseObserver({ name: "powered-by", onResponseHeaders(headers) { headers.set(header, value) }, }) }