Skip to content

Latest commit

 

History

History
430 lines (198 loc) · 9.43 KB

tough-cookie.md

File metadata and controls

430 lines (198 loc) · 9.43 KB

Home > tough-cookie

tough-cookie package

Classes

Class

Description

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.

CookieJar

A CookieJar is for storage and retrieval of Cookie objects as defined in RFC6265 - Section 5.3.

It also supports a pluggable persistence layer via Store.

MemoryCookieStore

An in-memory Store implementation for CookieJar. This is the default implementation used by CookieJar and supports both async and sync operations. Also supports serialization, getAllCookies, and removeAllCookies.

ParameterError

Represents a validation error.

Store

Base class for CookieJar stores.

The storage model for each CookieJar instance can be replaced with a custom implementation. The default is MemoryCookieStore.

Functions

Function

Description

canonicalDomain(domainName)

Transforms a domain name into a canonical domain name. The canonical domain name is a domain name that has been trimmed, lowercased, stripped of leading dot, and optionally punycode-encoded (Section 5.1.2 of RFC 6265). For the most part, this function is idempotent (calling the function with the output from a previous call returns the same output).

cookieCompare(a, b)

A comparison function that can be used with Array.sort(), which orders a list of cookies into the recommended order given in Step 2 of RFC6265 - Section 5.4.

The sort algorithm is, in order of precedence:

defaultPath(path)

Given a current request/response path, gives the path appropriate for storing in a cookie. This is basically the "directory" of a "file" in the path, but is specified by RFC6265 - Section 5.1.4.

domainMatch(domain, cookieDomain, canonicalize)

Answers "does this real domain match the domain in a cookie?". The domain is the "current" domain name and the cookieDomain is the "cookie" domain name. Matches according to RFC6265 - Section 5.1.3, but it helps to think of it as a "suffix match".

formatDate(date)

Format a Date into the preferred Internet standard format defined in RFC822 and updated in RFC1123.

fromJSON(str)

Does the reverse of Cookie.toJSON().

getPublicSuffix(domain, options)

Returns the public suffix of this hostname. The public suffix is the shortest domain name upon which a cookie can be set.

parse(str, options)

Parses a string into a Cookie object.

parseDate(cookieDate)

Parse a cookie date string into a Date. Parses according to RFC6265 - Section 5.1.1, not Date.parse().

pathMatch(reqPath, cookiePath)

Answers "does the request-path path-match a given cookie-path?" as per RFC6265 Section 5.1.4. This is essentially a prefix-match where cookiePath is a prefix of reqPath.

permuteDomain(domain, allowSpecialUseDomain)

Generates the permutation of all possible values that domainMatch() the given domain parameter. The array is in shortest-to-longest order. Useful when building custom Store implementations.

permutePath(path)

Generates the permutation of all possible values that pathMatch() the path parameter. The array is in longest-to-shortest order. Useful when building custom Store implementations.

Interfaces

Interface

Description

Callback

A callback function that accepts an error or a result.

CreateCookieJarOptions

Configuration settings to be used with a CookieJar.

CreateCookieOptions

Configurable values that can be set when creating a Cookie.

ErrorCallback

A callback function that only accepts an error.

GetCookiesOptions

Configuration options used when calling CookieJar.getCookies(...).

GetPublicSuffixOptions

Options for configuring how getPublicSuffix() behaves.

ParseCookieOptions

Optional configuration to be used when parsing cookies.

SerializedCookieJar

A JSON representation of a CookieJar.

SetCookieOptions

Configuration options used when calling CookieJar.setCookie(...)

Variables

Variable

Description

PrefixSecurityEnum

Cookie prefixes are a way to indicate that a given cookie was set with a set of attributes simply by inspecting the first few characters of the cookie's name. These are defined in RFC6265bis - Section 4.1.3.

The following values can be used to configure how a CookieJar enforces attribute restrictions for Cookie prefixes:

  • silent - Enable cookie prefix checking but silently ignores the cookie if conditions are not met. This is the default configuration for a CookieJar.

  • strict - Enables cookie prefix checking and will raise an error if conditions are not met.

  • unsafe-disabled - Disables cookie prefix checking.

version

The version of tough-cookie

Type Aliases

Type Alias

Description

Nullable

The inverse of NonNullable.

SerializedCookie

A JSON object that is created when Cookie.toJSON() is called. This object will contain the properties defined in Cookie.serializableProperties.