Cookie
interfacestring
string
Date|number
(optional)number
(optional)string
(optional)string
(optional)boolean
(optional)boolean
(optional)'String'|'Lax'|'None'
(optional)string[]
(optional) Left over attributes that weren't parsed.deleteCookie(headers, name[, attributes])
Sets the expiry time of the cookie to the unix epoch, causing browsers to delete it when received.
import { deleteCookie, Headers } from 'undici'
const headers = new Headers()
deleteCookie(headers, 'name')
console.log(headers.get('set-cookie')) // name=; Expires=Thu, 01 Jan 1970 00:00:00 GMT
Arguments:
Headers
string
{ path?: string, domain?: string }
(optional)Returns: void
getCookies(headers)
Parses the Cookie
header and returns a list of attributes and values.
import { getCookies, Headers } from 'undici'
const headers = new Headers({
cookie: 'get=cookies; and=attributes'
})
console.log(getCookies(headers)) // { get: 'cookies', and: 'attributes' }
Arguments:
Headers
Returns: Record<string, string>
getSetCookies(headers)
Parses all Set-Cookie
headers.
import { getSetCookies, Headers } from 'undici'
const headers = new Headers({ 'set-cookie': 'undici=getSetCookies; Secure' })
console.log(getSetCookies(headers))
// [
// {
// name: 'undici',
// value: 'getSetCookies',
// secure: true
// }
// ]
Arguments:
Headers
Returns: Cookie[]
setCookie(headers, cookie)
Appends a cookie to the Set-Cookie
header.
import { setCookie, Headers } from 'undici'
const headers = new Headers()
setCookie(headers, { name: 'undici', value: 'setCookie' })
console.log(headers.get('Set-Cookie')) // undici=setCookie
Arguments:
Headers
Cookie
Returns: void