Class: CookieStorage
Defined in: packages/core/src/storage/CookieStorage.ts:43
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.
Extends
Constructors
new CookieStorage()
new CookieStorage(
window
,request
,response
):CookieStorage
Defined in: packages/core/src/storage/CookieStorage.ts:182
Initializes the cookie storage.
Parameters
window
The window utility.
request
The current HTTP request.
response
The current HTTP response.
Returns
Example
cookie.set('cookie', 'value', { expires: 10 }); // cookie expires
// after 10s
cookie.set('cookie'); // delete cookie
Overrides
Accessors
$dependencies
Get Signature
get
static
$dependencies():Dependencies
Defined in: packages/core/src/storage/CookieStorage.ts:95
Returns
Methods
clear()
clear():
this
Defined in: packages/core/src/storage/CookieStorage.ts:280
Clears the storage of all entries.
Returns
this
This storage.
Overrides
delete()
delete(
name
,options
):this
Defined in: packages/core/src/storage/CookieStorage.ts:268
Deletes the cookie identified by the specified name.
Parameters
name
string
Name identifying the cookie.
options
CookieOptions
= {}
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
This storage.
Overrides
get()
get(
name
):undefined
|string
|number
|boolean
|Date
Defined in: packages/core/src/storage/CookieStorage.ts:216
Retrieves the value of the entry identified by the specified . The
method returns undefined
if the entry does not exists.
Entries set to the undefined
value can be tested for existence
using the link has
method.
Parameters
name
string
The key identifying the storage entry.
Returns
undefined
| string
| number
| boolean
| Date
The value of the storage entry.
Overrides
getCookiesStringForCookieHeader()
getCookiesStringForCookieHeader(
url
?):string
Defined in: packages/core/src/storage/CookieStorage.ts:318
Returns all cookies in this storage serialized to a string compatible
with the Cookie
HTTP header.
When url
is provided, the method validates the cookie security based on
the url
and the cookie's domain, path, and secure attributes.
Parameters
url?
string
Returns
string
All cookies in this storage serialized to a string
compatible with the Cookie
HTTP header.
getExpirationAsDate()
getExpirationAsDate(
expiration
):Date
Defined in: packages/core/src/storage/CookieStorage.ts:481
Converts the provided cookie expiration to a Date
instance.
Parameters
expiration
Cookie expiration in seconds
from now, or as a string compatible with the Date
constructor.
string
| number
| Date
Returns
Date
Cookie expiration as a Date
instance.
has()
has(
name
):boolean
Defined in: packages/core/src/storage/CookieStorage.ts:207
Returns true
if the entry identified by the specified key exists
in this storage.
Parameters
name
string
The key identifying the storage entry.
Returns
boolean
true
if the storage entry exists.
Overrides
init()
init(
options
,transformFunction
):this
Defined in: packages/core/src/storage/CookieStorage.ts:193
This method is used to finalize the initialization of the storage after the dependencies provided through the constructor have been prepared for use.
This method must be invoked only once and it must be the first method invoked on this instance.
Parameters
options
CookieOptions
= {}
transformFunction
Returns
this
This storage.
Overrides
keys()
keys():
Iterable
<string
>
Defined in: packages/core/src/storage/CookieStorage.ts:293
Returns an iterator for traversing the keys in this storage. The order in which the keys are traversed is undefined.
Returns
Iterable
<string
>
An iterator for traversing the keys in this
storage. The iterator also implements the iterable protocol,
returning itself as its own iterator, allowing it to be used in
a for..of
loop.
Overrides
parse()
parse():
void
Defined in: packages/core/src/storage/CookieStorage.ts:393
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.
Returns
void
parseFromSetCookieHeader()
parseFromSetCookieHeader(
cookiesString
,url
?):void
Defined in: packages/core/src/storage/CookieStorage.ts:357
Parses cookies from the provided Set-Cookie
HTTP header value.
When url
is provided, the method validates the cookie security based on
the url
and the cookie's domain, path, and secure attributes.
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
cookiesString
The value of the Set-Cookie
HTTP
header. When there are multiple cookies, the value can be
provided as an array of strings.
string
| string
[]
url?
string
Returns
void
recomputeCookieMaxAgeAndExpires()
recomputeCookieMaxAgeAndExpires(
options
):void
Defined in: packages/core/src/storage/CookieStorage.ts:459
Recomputes cookie's attributes maxAge and expires between each other.
Parameters
options
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
void
sanitizeCookieValue()
sanitizeCookieValue(
value
):string
Defined in: packages/core/src/storage/CookieStorage.ts:417
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
value
Cookie value
undefined
| string
| number
| boolean
| Date
Returns
string
Sanitized value
set()
set(
name
,value
,options
):this
Defined in: packages/core/src/storage/CookieStorage.ts:234
Sets the storage entry identified by the specified key to the provided value. The method creates the entry if it does not exist already.
Parameters
name
string
The key identifying the storage entry.
value
The storage entry value.
undefined
| string
| number
| boolean
| Date
options
CookieOptions
= {}
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.
Returns
this
This storage.
Overrides
size()
size():
number
Defined in: packages/core/src/storage/CookieStorage.ts:302
Returns the number of entries in this storage.
Returns
number
The number of entries in this storage.
Overrides
validateCookieSecurity()
static
validateCookieSecurity(cookie
,url
):boolean
Defined in: packages/core/src/storage/CookieStorage.ts:104
Filters invalid cookies based on the provided url. We try to check validity of the domain based on secure, path and domain definitions.
Parameters
cookie
url
string
Returns
boolean