reply.removeHeader()
Removes a previously set response header.
Syntax
reply.removeHeader(name: string) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
name | string | No | The header name to remove. |
Returns
FastifyReply — The reply, for chaining.
Examples
import Fastify from 'fastify';
const app = Fastify();
app.addHook('onSend', async (_req, reply, payload) => {
reply.removeHeader('x-powered-by');
return payload;
});
Notes
Must be called before the response is flushed (typically in an onSend
hook). Often used to strip identifying or default headers.