Home / Function/ handleRequest() — fastify Function Reference

handleRequest() — fastify Function Reference

Architecture documentation for the handleRequest() function in handle-request.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  0ea45009_d84c_8153_c668_66d7b8130f86["handleRequest()"]
  5f4e2742_950b_3da4_4ca3_7033016d7828["handle-request.js"]
  0ea45009_d84c_8153_c668_66d7b8130f86 -->|defined in| 5f4e2742_950b_3da4_4ca3_7033016d7828
  060f474d_3ec6_ccf3_5b20_c7c0bafc7898["handler()"]
  0ea45009_d84c_8153_c668_66d7b8130f86 -->|calls| 060f474d_3ec6_ccf3_5b20_c7c0bafc7898
  style 0ea45009_d84c_8153_c668_66d7b8130f86 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/handle-request.js lines 19–66

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)
    return
  }

  // Return 404 instead of 405 see https://github.com/fastify/fastify/pull/862 for discussion
  handler(request, reply)
}

Domain

Subdomains

Calls

Frequently Asked Questions

What does handleRequest() do?
handleRequest() is a function in the fastify codebase, defined in lib/handle-request.js.
Where is handleRequest() defined?
handleRequest() is defined in lib/handle-request.js at line 19.
What does handleRequest() call?
handleRequest() calls 1 function(s): handler.

Analyze Your Own Codebase

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

Try Supermodel Free