reply.header()
Sets a single response header.
Syntax
reply.header(name: string, value: string | number | string[]) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
name | string | No | The header name. |
value | string | number | string[] | No | The header value. |
Returns
FastifyReply — The reply, for chaining.
Examples
import Fastify from 'fastify';
const app = Fastify();
app.get('/download', async (_req, reply) => {
reply
.header('Content-Disposition', 'attachment; filename="data.txt"')
.type('text/plain');
return 'file body';
});
Notes
Headers must be set before send(). Use reply.headers() to set several at
once. Calling header() again with the same name overwrites the value.