diff --git a/index.js b/index.js index 6495af3d..8385ab99 100644 --- a/index.js +++ b/index.js @@ -91,13 +91,11 @@ async function fastifyStatic (fastify, opts) { } }) - wrap.on('pipe', function () { - if (request.method !== 'HEAD') { reply.send(wrap) } - }) - - wrap.on('finish', function () { - if (request.method === 'HEAD') { reply.send() } - }) + if (request.method === 'HEAD') { + wrap.on('finish', reply.send.bind(reply)) + } else { + wrap.on('pipe', reply.send.bind(reply, wrap)) + } if (setHeaders !== undefined) { stream.on('headers', setHeaders)