{
  "type": "module",
  "source": "doc/api/api-util.md",
  "modules": [
    {
      "textRaw": "Util",
      "name": "util",
      "introduced_in": "v1.2.0",
      "type": "module",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>A small set of utility helpers exposed for third-party implementations of the\n<a href=\"Dispatcher.html#class-dispatcher\"><code>Dispatcher</code></a> API. They cover the header-handling primitives undici uses\ninternally, so that custom dispatchers and handlers can normalize header names\nand parse raw header lists exactly the way undici does.</p>\n<pre><code class=\"language-mjs\">import { util } from 'undici'\n\nconst { parseHeaders, headerNameToString } = util\n</code></pre>\n<pre><code class=\"language-cjs\">const { util } = require('undici')\n\nconst { parseHeaders, headerNameToString } = util\n</code></pre>",
      "methods": [
        {
          "textRaw": "`parseHeaders(headers[, obj])`",
          "name": "parseHeaders",
          "type": "method",
          "meta": {
            "added": [
              "v1.2.0"
            ],
            "changes": [
              {
                "version": "v6.1.0",
                "pr-url": "https://github.com/nodejs/undici/pull/2501",
                "description": "Header names supplied as a `Buffer` are accepted and normalized."
              }
            ]
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`headers` {Array} A flat list of raw header entries where even indices are header names and odd indices are the corresponding values. Each entry is a {string}, {Buffer}, or an array of {string}/{Buffer}.",
                  "name": "headers",
                  "type": "Array",
                  "desc": "A flat list of raw header entries where even indices are header names and odd indices are the corresponding values. Each entry is a {string}, {Buffer}, or an array of {string}/{Buffer}."
                },
                {
                  "textRaw": "`obj` {Record}<{string}, {string|string}[]> An object to assign the parsed values to. When omitted, a new object is created. **Default:** `{}`.",
                  "name": "obj",
                  "type": "Record",
                  "default": "`{}`",
                  "desc": "<{string}, {string|string}[]> An object to assign the parsed values to. When omitted, a new object is created.",
                  "optional": true
                }
              ],
              "return": {
                "textRaw": "Returns: {Record}<{string}, {string|string}[]> The object the parsed headers were assigned to. When `obj` is provided, the same reference is returned.",
                "name": "return",
                "type": "Record",
                "desc": "<{string}, {string|string}[]> The object the parsed headers were assigned to. When `obj` is provided, the same reference is returned."
              }
            }
          ],
          "desc": "<p>Receives a flat list of raw header name/value pairs and returns them as an\nobject keyed by lowercased header name. Header names are normalized with\n<a href=\"#headernametostringvalue\"><code>headerNameToString()</code></a>, and <code>Buffer</code> values are decoded as <code>latin1</code>. When a\nheader name appears more than once, its values are collected into an array.</p>\n<pre><code class=\"language-mjs\">import { util } from 'undici'\n\nconst raw = ['Content-Type', 'text/plain', 'Set-Cookie', 'a=1', 'Set-Cookie', 'b=2']\n\nconsole.log(util.parseHeaders(raw))\n// { 'content-type': 'text/plain', 'set-cookie': [ 'a=1', 'b=2' ] }\n</code></pre>"
        },
        {
          "textRaw": "`headerNameToString(value)`",
          "name": "headerNameToString",
          "type": "method",
          "meta": {
            "added": [
              "v6.1.0"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`value` {string|Buffer} The header name to normalize.",
                  "name": "value",
                  "type": "string|Buffer",
                  "desc": "The header name to normalize."
                }
              ],
              "return": {
                "textRaw": "Returns: {string} The lowercased header name.",
                "name": "return",
                "type": "string",
                "desc": "The lowercased header name."
              }
            }
          ],
          "desc": "<p>Returns the lowercased form of a header name. The <code>value</code> may be provided as a\n<a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> or as a <a href=\"https://nodejs.org/api/buffer.html#class-buffer\"><code>&#x3C;Buffer></code></a>, in which case it is decoded as <code>latin1</code>. Common\nheader names are resolved through an internal lookup table for performance.</p>\n<pre><code class=\"language-mjs\">import { util } from 'undici'\n\nconsole.log(util.headerNameToString('Content-Type'))\n// 'content-type'\n\nconsole.log(util.headerNameToString(Buffer.from('X-Custom-Header')))\n// 'x-custom-header'\n</code></pre>"
        }
      ]
    }
  ]
}