HttpProtect.middleware() method
A middleware that rejects with a bare status code and no body.
Signature:
middleware(): (req: Request, res: Response, next: NextFunction) => Promise<void>;
Returns:
(req: Request, res: Response, next: NextFunction) => Promise<void>
An async middleware to hand to app.use().
Remarks
The leanest of the three: a rejected request gets its status and Response.end(), with no Content-Type and nothing written. Prefer HttpProtect.jsonMiddleware() for an API whose clients parse errors, or HttpProtect.textMiddleware() for something a human might read.
Mount it first, before body parsing and routing, so a rejected request costs as little as possible.
Example
app.use(new HttpProtect().middleware());
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.