{
  "type": "module",
  "source": "doc/api/api-cookies.md",
  "modules": [
    {
      "textRaw": "Cookies",
      "name": "cookies",
      "introduced_in": "v5.15.0",
      "type": "module",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p>A set of helpers for reading and writing HTTP cookies on a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Headers\"><code>Headers</code></a>\ninstance, following the <a href=\"https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis\">RFC 6265bis</a> cookie parsing and serialization\nalgorithm. They operate on the <code>Cookie</code> request header and the <code>Set-Cookie</code>\nresponse header.</p>\n<pre><code class=\"language-mjs\">import { getCookies, setCookie, deleteCookie, getSetCookies, parseCookie } from 'undici'\n</code></pre>\n<p>These functions do not manage a cookie jar or perform any network activity; they\nonly read from and mutate the supplied <code>Headers</code> object.</p>",
      "modules": [
        {
          "textRaw": "`Cookie`",
          "name": "`cookie`",
          "type": "module",
          "desc": "<p>The <code>Cookie</code> object describes a single cookie and its attributes. It is the\nreturn shape of <a href=\"#parsecookiecookie\"><code>parseCookie()</code></a> and <a href=\"#getsetcookiesheaders\"><code>getSetCookies()</code></a>, and the input\nshape accepted by <a href=\"#setcookieheaders-cookie\"><code>setCookie()</code></a>.</p>\n<ul>\n<li><code>name</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The cookie name.</li>\n<li><code>value</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The cookie value.</li>\n<li><code>expires</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date\"><code>&#x3C;Date></code></a> | <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The cookie expiry time, as a <code>Date</code> or a Unix\ntimestamp in seconds. (optional)</li>\n<li><code>maxAge</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#number_type\"><code>&#x3C;number></code></a> The number of seconds until the cookie expires. (optional)</li>\n<li><code>domain</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The hosts the cookie is sent to. (optional)</li>\n<li><code>path</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> The URL path that must exist for the cookie to be sent.\n(optional)</li>\n<li><code>secure</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#boolean_type\"><code>&#x3C;boolean></code></a> Whether the cookie is only sent over HTTPS. (optional)</li>\n<li><code>httpOnly</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#boolean_type\"><code>&#x3C;boolean></code></a> Whether the cookie is inaccessible to client-side\nJavaScript. (optional)</li>\n<li><code>sameSite</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a> Controls whether the cookie is sent with cross-site\nrequests. One of <code>'Strict'</code>, <code>'Lax'</code>, or <code>'None'</code>. (optional)</li>\n<li><code>unparsed</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a>[] Any attributes that were present in the <code>Set-Cookie</code>\nheader but not recognized, each formatted as <code>`name=value`</code>. (optional)</li>\n</ul>",
          "displayName": "`Cookie`"
        }
      ],
      "methods": [
        {
          "textRaw": "`getCookies(headers)`",
          "name": "getCookies",
          "type": "method",
          "meta": {
            "added": [
              "v5.15.0"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`headers` {Headers} The `Headers` to read the `Cookie` header from.",
                  "name": "headers",
                  "type": "Headers",
                  "desc": "The `Headers` to read the `Cookie` header from."
                }
              ],
              "return": {
                "textRaw": "Returns: {Record}<{string}, {string}> A map of cookie names to values.",
                "name": "return",
                "type": "Record",
                "desc": "<{string}, {string}> A map of cookie names to values."
              }
            }
          ],
          "desc": "<p>Parses the <code>Cookie</code> header of <code>headers</code> and returns its name/value pairs as a\nplain object. An empty object is returned when no <code>Cookie</code> header is present.</p>\n<pre><code class=\"language-mjs\">import { getCookies, Headers } from 'undici'\n\nconst headers = new Headers({\n  cookie: 'get=cookies; and=attributes'\n})\n\nconsole.log(getCookies(headers)) // { get: 'cookies', and: 'attributes' }\n</code></pre>"
        },
        {
          "textRaw": "`deleteCookie(headers, name[, attributes])`",
          "name": "deleteCookie",
          "type": "method",
          "meta": {
            "added": [
              "v5.15.0"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`headers` {Headers} The `Headers` to append the expiring cookie to.",
                  "name": "headers",
                  "type": "Headers",
                  "desc": "The `Headers` to append the expiring cookie to."
                },
                {
                  "textRaw": "`name` {string} The name of the cookie to delete.",
                  "name": "name",
                  "type": "string",
                  "desc": "The name of the cookie to delete."
                },
                {
                  "textRaw": "`attributes` {Object} (optional)",
                  "name": "attributes",
                  "type": "Object",
                  "desc": "(optional)",
                  "options": [
                    {
                      "textRaw": "`path` {string} The path the cookie was scoped to. **Default:** `null`.",
                      "name": "path",
                      "type": "string",
                      "default": "`null`",
                      "desc": "The path the cookie was scoped to."
                    },
                    {
                      "textRaw": "`domain` {string} The domain the cookie was scoped to. **Default:** `null`.",
                      "name": "domain",
                      "type": "string",
                      "default": "`null`",
                      "desc": "The domain the cookie was scoped to."
                    }
                  ],
                  "optional": true
                }
              ],
              "return": {
                "textRaw": "Returns: {undefined}",
                "name": "return",
                "type": "undefined"
              }
            }
          ],
          "desc": "<p>Appends a <code>Set-Cookie</code> header to <code>headers</code> that expires the named cookie by\nsetting its expiry time to the Unix epoch, causing a client to delete it on\nreceipt. The optional <code>path</code> and <code>domain</code> must match those of the cookie being\nremoved.</p>\n<pre><code class=\"language-mjs\">import { deleteCookie, Headers } from 'undici'\n\nconst headers = new Headers()\ndeleteCookie(headers, 'name')\n\nconsole.log(headers.get('set-cookie')) // name=; Expires=Thu, 01 Jan 1970 00:00:00 GMT\n</code></pre>"
        },
        {
          "textRaw": "`getSetCookies(headers)`",
          "name": "getSetCookies",
          "type": "method",
          "meta": {
            "added": [
              "v5.15.0"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`headers` {Headers} The `Headers` to read the `Set-Cookie` headers from.",
                  "name": "headers",
                  "type": "Headers",
                  "desc": "The `Headers` to read the `Set-Cookie` headers from."
                }
              ],
              "return": {
                "textRaw": "Returns: {Cookie}[] The parsed cookies, or an empty array when none are present.",
                "name": "return",
                "type": "Cookie",
                "desc": "[] The parsed cookies, or an empty array when none are present."
              }
            }
          ],
          "desc": "<p>Parses every <code>Set-Cookie</code> header of <code>headers</code> and returns the resulting\n<a href=\"#cookie\"><code>Cookie</code></a> objects. A header that fails to parse yields a <code>null</code> entry at its\nposition in the returned array.</p>\n<pre><code class=\"language-mjs\">import { getSetCookies, Headers } from 'undici'\n\nconst headers = new Headers({ 'set-cookie': 'undici=getSetCookies; Secure' })\n\nconsole.log(getSetCookies(headers))\n// [\n//   {\n//     name: 'undici',\n//     value: 'getSetCookies',\n//     secure: true\n//   }\n// ]\n</code></pre>"
        },
        {
          "textRaw": "`setCookie(headers, cookie)`",
          "name": "setCookie",
          "type": "method",
          "meta": {
            "added": [
              "v5.15.0"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`headers` {Headers} The `Headers` to append the `Set-Cookie` header to.",
                  "name": "headers",
                  "type": "Headers",
                  "desc": "The `Headers` to append the `Set-Cookie` header to."
                },
                {
                  "textRaw": "`cookie` {Cookie} The cookie to serialize. See `Cookie`.",
                  "name": "cookie",
                  "type": "Cookie",
                  "desc": "The cookie to serialize. See `Cookie`."
                }
              ],
              "return": {
                "textRaw": "Returns: {undefined}",
                "name": "return",
                "type": "undefined"
              }
            }
          ],
          "desc": "<p>Serializes <code>cookie</code> and appends it to the <code>Set-Cookie</code> header of <code>headers</code>. When\nthe cookie name is empty, serialization yields no value and no header is\nappended.</p>\n<pre><code class=\"language-mjs\">import { setCookie, Headers } from 'undici'\n\nconst headers = new Headers()\nsetCookie(headers, { name: 'undici', value: 'setCookie' })\n\nconsole.log(headers.get('Set-Cookie')) // undici=setCookie\n</code></pre>"
        },
        {
          "textRaw": "`parseCookie(cookie)`",
          "name": "parseCookie",
          "type": "method",
          "meta": {
            "added": [
              "v7.0.0"
            ],
            "changes": []
          },
          "signatures": [
            {
              "params": [
                {
                  "textRaw": "`cookie` {string} A `Set-Cookie` header value.",
                  "name": "cookie",
                  "type": "string",
                  "desc": "A `Set-Cookie` header value."
                }
              ],
              "return": {
                "textRaw": "Returns: {Cookie|null} The parsed cookie, or `null` if `cookie` is invalid.",
                "name": "return",
                "type": "Cookie|null",
                "desc": "The parsed cookie, or `null` if `cookie` is invalid."
              }
            }
          ],
          "desc": "<p>Parses a single <code>Set-Cookie</code> header value into a <a href=\"#cookie\"><code>Cookie</code></a> object. <code>null</code> is\nreturned when the value contains control characters or otherwise cannot be\nparsed.</p>\n<pre><code class=\"language-mjs\">import { parseCookie } from 'undici'\n\nconsole.log(parseCookie('undici=getSetCookies; Secure; SameSite=Lax'))\n// {\n//   name: 'undici',\n//   value: 'getSetCookies',\n//   secure: true,\n//   sameSite: 'Lax'\n// }\n</code></pre>\n<p>The cookie value is returned exactly as it appears in the header; percent-encoded\nsequences such as <code>%20</code> or <code>%0D%0A</code> are not decoded. The <code>sameSite</code> attribute is\nonly set when the value is a case-insensitive match for <code>Strict</code>, <code>Lax</code>, or\n<code>None</code>.</p>"
        }
      ]
    }
  ]
}