Home / File/ handle-request.js — fastify Source File

handle-request.js — fastify Source File

Architecture documentation for handle-request.js, a javascript file in the fastify codebase.

Entity Profile

Relationship Graph

Source Code

'use strict'

const diagnostics = require('node:diagnostics_channel')
const ContentType = require('./content-type')
const wrapThenable = require('./wrap-thenable')
const { validate: validateSchema } = require('./validation')
const { preValidationHookRunner, preHandlerHookRunner } = require('./hooks')
const { FST_ERR_CTP_INVALID_MEDIA_TYPE } = require('./errors')
const { setErrorStatusCode } = require('./error-status')
const {
  kReplyIsError,
  kRouteContext,
  kFourOhFourContext,
  kSupportedHTTPMethods
} = require('./symbols')

const channels = diagnostics.tracingChannel('fastify.request.handler')

function handleRequest (err, request, reply) {
  if (reply.sent === true) return
  if (err != null) {
    reply[kReplyIsError] = true
    reply.send(err)
    return
  }

  const method = request.method

  if (this[kSupportedHTTPMethods].bodyless.has(method)) {
    handler(request, reply)
    return
  }

  if (this[kSupportedHTTPMethods].bodywith.has(method)) {
    const headers = request.headers
    const ctHeader = headers['content-type']

    if (ctHeader === undefined) {
      const contentLength = headers['content-length']
      const transferEncoding = headers['transfer-encoding']
      const isEmptyBody = transferEncoding === undefined &&
        (contentLength === undefined || contentLength === '0')

      if (isEmptyBody) {
        // Request has no body to parse
        handler(request, reply)
        return
      }

      request[kRouteContext].contentTypeParser.run('', handler, request, reply)
      return
    }

    const contentType = new ContentType(ctHeader)
    if (contentType.isValid === false) {
      reply[kReplyIsError] = true
      reply.status(415).send(new FST_ERR_CTP_INVALID_MEDIA_TYPE())
      return
    }
    request[kRouteContext].contentTypeParser.run(contentType.toString(), handler, request, reply)
// ... (136 more lines)

Domain

Subdomains

Frequently Asked Questions

What does handle-request.js do?
handle-request.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 handle-request.js?
handle-request.js defines 6 function(s): handleRequest, handler, preHandlerCallback, preHandlerCallbackInner, preValidationCallback, validationCompleted.
Where is handle-request.js in the architecture?
handle-request.js is located at lib/handle-request.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