Home / Function/ buildRequestWithTrustProxy() — fastify Function Reference

buildRequestWithTrustProxy() — fastify Function Reference

Architecture documentation for the buildRequestWithTrustProxy() function in request.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  0853a9df_938e_78e1_d709_3314e1b8d395["buildRequestWithTrustProxy()"]
  3043e2d7_25f2_f891_cdeb_063719d4cac2["request.js"]
  0853a9df_938e_78e1_d709_3314e1b8d395 -->|defined in| 3043e2d7_25f2_f891_cdeb_063719d4cac2
  23ccc8c0_8bbd_453a_2952_2ddfbe774148["buildRequest()"]
  23ccc8c0_8bbd_453a_2952_2ddfbe774148 -->|calls| 0853a9df_938e_78e1_d709_3314e1b8d395
  b3890e54_c12f_beef_85cc_40bd4eb33c60["buildRegularRequest()"]
  0853a9df_938e_78e1_d709_3314e1b8d395 -->|calls| b3890e54_c12f_beef_85cc_40bd4eb33c60
  cd8b56ea_67de_c076_301b_e6254e544e9d["getTrustProxyFn()"]
  0853a9df_938e_78e1_d709_3314e1b8d395 -->|calls| cd8b56ea_67de_c076_301b_e6254e544e9d
  3d6badf9_a8b3_f33d_548e_1ac94e7171bd["getLastEntryInMultiHeaderValue()"]
  0853a9df_938e_78e1_d709_3314e1b8d395 -->|calls| 3d6badf9_a8b3_f33d_548e_1ac94e7171bd
  style 0853a9df_938e_78e1_d709_3314e1b8d395 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/request.js lines 97–143

function buildRequestWithTrustProxy (R, trustProxy) {
  const _Request = buildRegularRequest(R)
  const proxyFn = getTrustProxyFn(trustProxy)

  // This is a more optimized version of decoration
  _Request[kHasBeenDecorated] = true

  Object.defineProperties(_Request.prototype, {
    ip: {
      get () {
        const addrs = proxyAddr.all(this.raw, proxyFn)
        return addrs[addrs.length - 1]
      }
    },
    ips: {
      get () {
        return proxyAddr.all(this.raw, proxyFn)
      }
    },
    host: {
      get () {
        if (this.ip !== undefined && this.headers['x-forwarded-host']) {
          return getLastEntryInMultiHeaderValue(this.headers['x-forwarded-host'])
        }
        /**
         * The last fallback supports the following cases:
         * 1. http.requireHostHeader === false
         * 2. HTTP/1.0 without a Host Header
         * 3. Headers schema that may remove the Host Header
         */
        return this.headers.host ?? this.headers[':authority'] ?? ''
      }
    },
    protocol: {
      get () {
        if (this.headers['x-forwarded-proto']) {
          return getLastEntryInMultiHeaderValue(this.headers['x-forwarded-proto'])
        }
        if (this.socket) {
          return this.socket.encrypted ? 'https' : 'http'
        }
      }
    }
  })

  return _Request
}

Domain

Subdomains

Defined In

Called By

Frequently Asked Questions

What does buildRequestWithTrustProxy() do?
buildRequestWithTrustProxy() is a function in the fastify codebase, defined in lib/request.js.
Where is buildRequestWithTrustProxy() defined?
buildRequestWithTrustProxy() is defined in lib/request.js at line 97.
What does buildRequestWithTrustProxy() call?
buildRequestWithTrustProxy() calls 3 function(s): buildRegularRequest, getLastEntryInMultiHeaderValue, getTrustProxyFn.
What calls buildRequestWithTrustProxy()?
buildRequestWithTrustProxy() is called by 1 function(s): buildRequest.

Analyze Your Own Codebase

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

Try Supermodel Free