Home / Function/ header() — fastify Function Reference

header() — fastify Function Reference

Architecture documentation for the header() function in reply.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  c6d9a0f0_0f24_2129_fb32_dcc24b82bc25["header()"]
  4bcd71dc_1ec2_5fe8_b8ff_4a371e392925["reply.js"]
  c6d9a0f0_0f24_2129_fb32_dcc24b82bc25 -->|defined in| 4bcd71dc_1ec2_5fe8_b8ff_4a371e392925
  449bf06a_1273_21bf_add6_6deca225c896["headers()"]
  449bf06a_1273_21bf_add6_6deca225c896 -->|calls| c6d9a0f0_0f24_2129_fb32_dcc24b82bc25
  ec055405_4033_df3a_534f_a70521a62963["redirect()"]
  ec055405_4033_df3a_534f_a70521a62963 -->|calls| c6d9a0f0_0f24_2129_fb32_dcc24b82bc25
  8460cb7c_51e5_baba_0f16_9ea8d190d139["onSendEnd()"]
  8460cb7c_51e5_baba_0f16_9ea8d190d139 -->|calls| c6d9a0f0_0f24_2129_fb32_dcc24b82bc25
  style c6d9a0f0_0f24_2129_fb32_dcc24b82bc25 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/reply.js lines 241–260

Reply.prototype.header = function (key, value = '') {
  key = key.toLowerCase()

  if (this[kReplyHeaders][key] && key === 'set-cookie') {
    // https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.2
    if (typeof this[kReplyHeaders][key] === 'string') {
      this[kReplyHeaders][key] = [this[kReplyHeaders][key]]
    }

    if (Array.isArray(value)) {
      Array.prototype.push.apply(this[kReplyHeaders][key], value)
    } else {
      this[kReplyHeaders][key].push(value)
    }
  } else {
    this[kReplyHeaders][key] = value
  }

  return this
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does header() do?
header() is a function in the fastify codebase, defined in lib/reply.js.
Where is header() defined?
header() is defined in lib/reply.js at line 241.
What calls header()?
header() is called by 3 function(s): headers, onSendEnd, redirect.

Analyze Your Own Codebase

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

Try Supermodel Free