title: How do I send a HEAD request for a static sendFile in fastify?
body: <p>When I try to send a <code>HEAD</code> request for <code>sendFile</code> I get the following error:</p>
  
  <pre class="lang-js prettyprint-override"><code>app.head(filePath, { logLevel: LOG_LEVEL }, async (request, reply) =&gt; {
      console.log('head');
      try {
        const { '*': uriPath } = request.params;
        const isFile = !!uriPath.match(/\.[a-zA-Z0-9]{1,5}(\?.*)?/);
        if (isFile) {
          setCacheControl(reply, FILE_CACHE_CONTROL_MAX_AGE);
          reply.sendFile(uriPath);
        } else {
          const indexPath = 'index.html';
          const indexStr = await fs.readFile(path.join(serveRoot, indexPath), {
            encoding: 'utf-8',
          });
          const indexPayload = await injectEnv(indexStr);
          setCacheControl(reply, INDEX_CACHE_CONTROL_MAX_AGE);
          reply.type('text/html');
          reply.send(indexPayload);
        }
      } catch (e) {
        console.error(e);
      }
    });
  </code></pre>
  
  <pre><code>web_1  | {"level":50,"time":1580244056047,"pid":1,"hostname":"3ee631923a16","reqId":5,"err":{"type":"FastifyError","message":"FST_ERR_PROMISE_NOT_FULLFILLED: Promise may not be fulfilled with 'undefined' when statusCode is not 204","stack":"FastifyError [FST_ERR_PROMISE_NOT_FULLFILLED]: FST_ERR_PROMISE_NOT_FULLFILLED: Promise may not be fulfilled with 'undefined' when statusCode is not 204\n    at /usr/src/server/node_modules/fastify/lib/wrapThenable.js:34:30\n    at processTicksAndRejections (internal/process/task_queues.js:85:5)","name":"FastifyError [FST_ERR_PROMISE_NOT_FULLFILLED]","code":"FST_ERR_PROMISE_NOT_FULLFILLED","statusCode":500},"msg":"Promise may not be fulfilled with 'undefined' when statusCode is not 204","v":1}
  </code></pre>
  
  <p>The way that express handles this is by simply passing through <code>HEAD</code> requests to the <code>GET</code> method, and then letting <code>send</code> (the underlying package that sends responses for both fastify and express) handle it <a href="https://github.com/pillarjs/send/blob/ea1748a3b3e00dbcbb0629cf368ced575c6ab7d6/index.js#L710" rel="nofollow noreferrer">here</a> by not sending the output but sending the headers.</p>
  
  <p>But fastify seems to incorrectly mark this as an error <a href="https://github.com/fastify/fastify/blob/0d6055d3e07b726c9bfbc779550adf78dab967f3/lib/wrapThenable.js#L33" rel="nofollow noreferrer">here</a></p>