Class: CookieStorage

CookieStorage

Storage of cookies, mirroring the cookies to the current request / response at the server side and the document.cookie property at the client side. The storage caches the cookies internally.


new CookieStorage(window, request, response)

Initializes the cookie storage.

Parameters:
Name Type Description
window Window

The window utility.

request Request

The current HTTP request.

response Response

The current HTTP response.

Members


_options :Object

The overriding cookie attribute values.

Type:
  • Object

_request :Request

The current HTTP request. This field is used at the server side.

Type:

_response :Response

The current HTTP response. This field is used at the server side.

Type:

_transformFunction :Object

Transform encode and decode functions for cookie value.

Type:
  • Object

_window :Window

The window utility used to determine whether the IMA is being run at the client or at the server.

Type:

Methods


_extractCookie(cookieString)

Extract cookie name, value and options from cookie string.

Parameters:
Name Type Description
cookieString string

The value of the Set-Cookie HTTP header.

Returns:
Type
Object

_extractNameAndValue(pair, pairIndex)

Extract name and value for defined pair and pair index.

Parameters:
Name Type Description
pair string
pairIndex number
Returns:
Type
Array.<?(boolean|string|Date)>

_firstLetterToLowerCase(word)

Creates a copy of the provided word (or text) that has its first character converted to lower case.

Parameters:
Name Type Description
word string

The word (or any text) that should have its first character converted to lower case.

Returns:

A copy of the provided string with its first character converted to lower case.

Type
string

_generateCookieString(name, value, options)

Generates a string representing the specified cookied, usable either with the document.cookie property or the Set-Cookie HTTP header.

(Note that the Cookie HTTP header uses a slightly different syntax.)

Parameters:
Name Type Description
name string

The cookie name.

value boolean | number | string

The cookie value, will be converted to string.

options Object

Cookie attributes. Only the attributes listed in the type annotation of this field are supported. For documentation and full list of cookie attributes see http://tools.ietf.org/html/rfc2965#page-5

Returns:

A string representing the cookie. Setting this string to the document.cookie property will set the cookie to the browser's cookie storage.

Type
string

_getExpirationAsDate(expiration)

Converts the provided cookie expiration to a Date instance.

Parameters:
Name Type Description
expiration number | string | Date

Cookie expiration in seconds from now, or as a string compatible with the Date constructor.

Returns:

Cookie expiration as a Date instance.

Type
Date

_parse()

Parses cookies from a cookie string and sets the parsed cookies to the internal storage.

The method obtains the cookie string from the request's Cookie HTTP header when used at the server side, and the document.cookie property at the client side.


_recomputeCookieMaxAgeAndExpires(options)

Recomputes cookie's attributes maxAge and expires between each other.

Parameters:
Name Type Description
options Object

Cookie attributes. Only the attributes listed in the type annotation of this field are supported. For documentation and full list of cookie attributes see http://tools.ietf.org/html/rfc2965#page-5


_sanitizeCookieValue(value)

Sanitize cookie value by rules in (@see http://tools.ietf.org/html/rfc6265#section-4r.1.1). Erase all invalid characters from cookie value.

Parameters:
Name Type Description
value string

Cookie value

Returns:

Sanitized value

Type
string

clear()


delete(name [, options])

Deletes the cookie identified by the specified name.

Parameters:
Name Type Argument Description
name string

Name identifying the cookie.

options Object <optional>

The cookie options. The domain and path specify the cookie's domain and path. The httpOnly and secure flags set the flags of the same name of the cookie.

Returns:

This storage.

Type
Storage

get()


getCookiesStringForCookieHeader()

Returns all cookies in this storage serialized to a string compatible with the Cookie HTTP header.

Returns:

All cookies in this storage serialized to a string compatible with the Cookie HTTP header.

Type
string

has()


init(options, transformFunction)

Parameters:
Name Type Description
options Object
transformFunction Object

keys()


parseFromSetCookieHeader(setCookieHeader)

Parses cookies from the provided Set-Cookie HTTP header value.

The parsed cookies will be set to the internal storage, and the current HTTP response (via the Set-Cookie HTTP header) if at the server side, or the browser (via the document.cookie property).

Parameters:
Name Type Description
setCookieHeader string

The value of the Set-Cookie HTTP header.


set(name, value [, options])

Parameters:
Name Type Argument Description
name string

The key identifying the storage entry.

value *

The storage entry value.

options Object <optional>

The cookie options. The maxAge is the maximum age in seconds of the cookie before it will be deleted, the expires is an alternative to that, specifying the moment at which the cookie will be discarded. The domain and path specify the cookie's domain and path. The httpOnly and secure flags set the flags of the same name of the cookie.


size()