Home / File/ head-route.js — fastify Source File

head-route.js — fastify Source File

Architecture documentation for head-route.js, a javascript file in the fastify codebase.

Entity Profile

Relationship Graph

Source Code

'use strict'
function headRouteOnSendHandler (req, reply, payload, done) {
  // If payload is undefined
  if (payload === undefined) {
    reply.header('content-length', '0')
    done(null, null)
    return
  }

  // node:stream
  if (typeof payload.resume === 'function') {
    payload.on('error', (err) => {
      reply.log.error({ err }, 'Error on Stream found for HEAD route')
    })
    payload.resume()
    done(null, null)
    return
  }

  // node:stream/web
  if (typeof payload.getReader === 'function') {
    payload.cancel('Stream cancelled by HEAD route').catch((err) => {
      reply.log.error({ err }, 'Error on Stream found for HEAD route')
    })
    done(null, null)
    return
  }

  const size = '' + Buffer.byteLength(payload)

  reply.header('content-length', size)

  done(null, null)
}

function parseHeadOnSendHandlers (onSendHandlers) {
  if (onSendHandlers == null) return headRouteOnSendHandler
  return Array.isArray(onSendHandlers)
    ? [...onSendHandlers, headRouteOnSendHandler]
    : [onSendHandlers, headRouteOnSendHandler]
}

module.exports = {
  parseHeadOnSendHandlers
}

Domain

Subdomains

Frequently Asked Questions

What does head-route.js do?
head-route.js is a source file in the fastify codebase, written in javascript. It belongs to the CoreKernel domain, LifecycleManager subdomain.
What functions are defined in head-route.js?
head-route.js defines 2 function(s): headRouteOnSendHandler, parseHeadOnSendHandlers.
Where is head-route.js in the architecture?
head-route.js is located at lib/head-route.js (domain: CoreKernel, subdomain: LifecycleManager, directory: lib).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free