Home > tough-cookie > Cookie
An HTTP cookie (web cookie, browser cookie) is a small piece of data that a server sends to a user's web browser. It is defined in RFC6265.
Signature:
export declare class Cookie
Constructor |
Modifiers |
Description |
---|---|---|
Create a new Cookie instance. |
Property |
Modifiers |
Type |
Description |
---|---|---|---|
Date | 'Infinity' | null |
Set to the date and time when a Cookie is initially stored or a matching cookie is received that replaces an existing cookie (See RFC6265 Section 5.3). Also used to maintain ordering among cookies. Among cookies that have equal-length path fields, cookies with earlier creation-times are listed before cookies with later creation-times (See RFC6265 Section 5.4). | ||
number |
A global counter used to break ordering ties between two cookies that have equal-length path fields and the same creation-time. | ||
string | null |
The 'Domain' attribute of the cookie represents the domain the cookie belongs to (See RFC6265 Section 5.2.3). | ||
Date | 'Infinity' | null |
The 'Expires' attribute of the cookie (See RFC6265 Section 5.2.1). | ||
string[] | null |
Contains attributes which are not part of the defined spec but match the | ||
boolean | null |
A boolean flag indicating if a cookie is a host-only cookie (i.e.; when the request's host exactly matches the domain of the cookie) or not (See RFC6265 Section 5.3). | ||
boolean |
The 'HttpOnly' flag of the cookie indicates if the cookie is inaccessible to client scripts or not (See RFC6265 Section 5.2.6). | ||
string |
The name or key of the cookie | ||
Date | 'Infinity' | null |
Set to the date and time when a cookie was initially stored (RFC6265 Section 5.3) and updated whenever the cookie is retrieved from the CookieJar (RFC6265 Section 5.4). | ||
number | 'Infinity' | '-Infinity' | null |
The 'Max-Age' attribute of the cookie (See RFC6265 Section 5.2.2). | ||
string | null |
The 'Path' attribute of the cookie represents the path of the cookie (See RFC6265 Section 5.2.4). | ||
boolean | null |
A boolean flag indicating if a cookie had no 'Path' attribute and the default path was used (See RFC6265 Section 5.2.4). | ||
string | undefined |
The 'SameSite' attribute of a cookie as defined in RFC6265bis (See RFC6265bis (v13) Section 5.2). | ||
boolean |
The 'Secure' flag of the cookie indicates if the scope of the cookie is limited to secure channels (e.g.; HTTPS) or not (See RFC6265 Section 5.2.5). | ||
|
readonly ["key", "value", "expires", "maxAge", "domain", "path", "secure", "httpOnly", "extensions", "hostOnly", "pathIsDefault", "creation", "lastAccessed", "sameSite"] |
Cookie properties that will be serialized when using Cookie.fromJSON() and Cookie.toJSON(). | |
string |
The value of the cookie |
Method |
Modifiers |
Description |
---|---|---|
Calls canonicalDomain() with the Cookie.domain property. | ||
Alias for Cookie.canonicalizedDomain() | ||
Does a deep clone of this cookie, implemented exactly as | ||
Encodes to a | ||
Similar to Cookie.expiryTime(), computes the absolute unix-epoch milliseconds that this cookie expires and returns it as a Date. The "Max-Age" attribute takes precedence over "Expires" (as per the RFC). The Cookie.lastAccessed attribute (or the If Expires (Cookie.expires) is set, that's returned. | ||
Computes the absolute unix-epoch milliseconds that this cookie expires. The "Max-Age" attribute takes precedence over "Expires" (as per the RFC). The Cookie.lastAccessed attribute (or the If Expires (Cookie.expires) is set, that's returned. | ||
|
Does the reverse of Cookie.toJSON(). | |
Indicates if the cookie has been persisted to a store or not. | ||
|
Parses a string into a Cookie object. | |
Sets the 'Expires' attribute on a cookie. | ||
Sets the 'Max-Age' attribute (in seconds) on a cookie. | ||
For convenience in using | ||
Encodes to a | ||
Computes the TTL relative to now (milliseconds). | ||
(BETA) Validates cookie attributes for semantic correctness. Useful for "lint" checking any |