cookies
A cookies module is available to assist in cookie manipulation. This module exports two structs, Cookies and SetCookie, each corresponding to one “Cookie” or “Set-Cookie” header respectively.
📘 Cookies are often user or session specific, stripping the cookie helps improve the offload of cached objects.
To keep the
Set-Cookieheader, you can use the<edgeservices:cookie.pass-set-cookie-policy>metadata tag. This metadata tag lets you keep theSet-Cookieheader modifications made during theonClientResponseevent.
Properties for the SetCookie Object
name
Sets the cookie name.
value
Sets the cookie value.
domain
Optional Sets the domain name for the cookie.
expires
Optional Sets the expiry date of the cookie in GMT. If an expiry date is not specified or set to 0, a session cookie is created.
httpOnly
Optional Helps mitigate the risk of a client side script accessing a protected cookie (if supported by the browser).
maxAge
Optional Sets the expiry time relative to the current time in seconds. A value of zero tells the browser to delete the cookie immediately.
path
Optional Sets the path for the cookie.
sameSite
Optional Allows servers to prevent cookies from being sent using cross-site requests (where Site is defined by the registerable domain). This provides some protection against cross-site request forgery attacks (CSRF).
secure
Optional Specifies the cookies that can only be used with HTTPS only.
Methods for SetCookie()
Constructor for a new “SetCookie” object. Holds a specific Set-Cookie header representation and the SetCookie object that corresponds to the “Set-Cookie” header.
Parameters
Review the table below for information about the available parameters.
options
toHeader([options])
Returns the string value to use when setting the Cookie header, encoding values by default.
Parameters
Review the table below for information about the available parameters.
options
Methods for Cookies()
Constructor for a new “Cookies” object to hold cookies.
Parameters
Review the table below for information about the available parameters.
options
toHeader()
Returns the string value to use when setting the Cookie header, encoding values by default.
Parameters
Review the table below for information about the available parameters.
options
get()
Returns the first instance of the cookie matching the specified cookie name.
Review the table below for information about the available parameters.
getAll()
Returns all cookie instances matching the specified cookie name.
Parameters
Review the table below for information about the available parameters.
names()
Returns the names of all existing cookies held by the specified cookies object. Array of Strings.
add()
Adds a cookie to an object containing all the cookies.
Parameters
Review the table below for information about the available parameters.
delete()
Removes all cookies with a given name.
Parameters
Review the table below for information about the available parameters.