Documentation / @zerotal/core / index / withHeaders
Function: withHeaders()
withHeaders(
res,headers):Response
Defined in: http/withHeaders.ts:16
Return a copy of res with the given headers added/overwritten.
A Response produced by Response.redirect() (or Response.error()) has an
immutable headers guard — calling res.headers.set(...) on it throws.
Middleware that decorates the downstream response (CORS, security headers,
rate-limit info, …) must therefore reconstruct rather than mutate in place.
new Response(body, ...) always yields a mutable guard, so the copy is safe.
Parameters
res
Response
headers
Record<string, string>
Returns
Response
Example
async handle(_, next) {
const res = await next();
return res ? withHeaders(res, { "X-Frame-Options": "DENY" }) : res;
}