reply.hijack()

Takes manual control of the response, bypassing Fastify lifecycle handling.

Since Fastify 5 Spec ↗

Syntax

reply.hijack()

Returns

FastifyReply — The reply; you must end raw yourself.

Examples

import Fastify from 'fastify';

const app = Fastify();

app.get('/stream', (_req, reply) => {
  reply.hijack();
  reply.raw.writeHead(200, { 'Content-Type': 'text/plain' });
  reply.raw.write('chunk-1\n');
  reply.raw.end('done\n');
});

Notes

After hijack(), Fastify stops managing the response, so onSend and the serializer are skipped and you must write to reply.raw and end it yourself. Used for SSE, manual streaming, or WebSocket upgrades.