Response interface
The minimum a response object must provide for the middlewares to answer with.
Signature:
export interface Response
Remarks
Structural on purpose, so express, Fastify's compatibility layer, a bare http.ServerResponse wrapper or a test double all satisfy it without this package depending on any of them.
Response.header() and Response.setHeader() are both optional because frameworks disagree on which they provide; HttpProtect.textMiddleware() and HttpProtect.jsonMiddleware() prefer header, fall back to setHeader, and simply send no Content-Type if neither is a function.
Methods
|
Method |
Description |
|---|---|
|
Ends the response. Called by every middleware on a rejected request, including after Response.send(). | |
|
(Optional) Express-style header setter, preferred when present. | |
|
Writes the response body. Given a plain string by HttpProtect.textMiddleware() and a JSON string by HttpProtect.jsonMiddleware(); never called by HttpProtect.middleware(), which answers with no body at all. | |
|
(Optional) Node-style header setter, used only when Response.header() is absent. | |
|
Sets the HTTP status code. Called with 429 or 418 before the body is sent. |
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.