reply.removeHeader()

Removes a previously set response header.

Since Fastify 5 Spec ↗

Syntax

reply.removeHeader(name: string)

Parameters

NameTypeRequiredDescription
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.