Script: Class dw.web.Cookie

Class Cookie

Represents an HTTP cookie used for storing information on a client browser. Cookies are passed along in the HTTP request and can be retrieved by calling dw.system.Request.getHttpCookies().

Cookies must comply with RFC6265. We recommend you use only printable ASCII characters without separators, such as a comma or equal sign. If JSON is used as a cookie value, it must be encoded.

Note: this class allows access to sensitive security-related data. Pay special attention to PCI DSS v3. requirements 2, 4, and 12.

See Request.getHttpCookies().

Constants

EMPTYNAME : String = "dw_emptyname__"

Default name for cookies with empty strings.

Properties

comment : String

The comment associated with the cookie.

domain : String

The domain associated with the cookie.

httpOnly : boolean

Identifies if the cookie is http-only.

maxAge : Number

The maximum age of the cookie, specified in seconds. By default, -1 indicating the cookie will persist until client shutdown.

name : String Read Only

The cookie's name.

path : String

The path for the cookie.

secure : boolean

Identifies if the cookie is secure.

value : String

The cookie's value.

version : Number

The version for the cookie. 0 means original Netscape cookie and 1 means RFC 2109 compliant cookie.

Constructor Summary

Cookie(name : String, value : String)

Constructs a new cookie using the specified name and value.

Method Summary

getComment() : String

Returns the comment associated with the cookie.

getDomain() : String

Returns the domain associated with the cookie.

getMaxAge() : Number

Returns the maximum age of the cookie, specified in seconds.

getName() : String

Returns the cookie's name.

getPath() : String

Returns the path for the cookie.

getSecure() : boolean

Identifies if the cookie is secure.

getValue() : String

Returns the cookie's value.

getVersion() : Number

Returns the version for the cookie.

isHttpOnly() : boolean

Identifies if the cookie is http-only.

setComment(comment : String) : void

Sets the comment associated with the cookie.

setDomain(domain : String) : void

Sets the domain associated with the cookie.

setHttpOnly(httpOnly : boolean) : void

Sets the http-only state for the cookie.

setMaxAge(age : Number) : void

Sets the maximum age of the cookie in seconds.

setPath(path : String) : void

Sets the path for the cookie.

setSecure(secure : boolean) : void

Sets the secure state for the cookie.

setValue(value : String) : void

Sets the cookie's value.

setVersion(version : Number) : void

Sets the version for the cookie.

Methods inherited from class Object

assign, create, create, defineProperties, defineProperty, entries, freeze, fromEntries, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, getPrototypeOf, hasOwnProperty, is, isExtensible, isFrozen, isPrototypeOf, isSealed, keys, preventExtensions, propertyIsEnumerable, seal, setPrototypeOf, toLocaleString, toString, valueOf, values

Constructor Detail

publicCookie(name : String, value : String)

Constructs a new cookie using the specified name and value.

Parameters:

name - the name for the cookie.

value - the cookie's value.


Method Detail

getComment

getComment() : String

Returns the comment associated with the cookie.

Returns:

the comment associated with the cookie.

getDomain

getDomain() : String

Returns the domain associated with the cookie.

Returns:

the domain associated with the cookie.


getMaxAge

getMaxAge() : Number

Returns the maximum age of the cookie, specified in seconds. By default, -1 indicating the cookie will persist until client shutdown.

Returns:

an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie persists until client shutdown


getName

getName() : String

Returns the cookie's name.

Returns:

the cookie's name.


getPath

getPath() : String

Returns the path for the cookie.

Returns:

the path for the cookie.


getSecure

getSecure() : boolean

Identifies if the cookie is secure.

Returns:

true if the cookie is secure, false otherwise.


getValue

getValue() : String

Returns the cookie's value.

Returns:

the cookie's value.


getVersion

getVersion() : Number

Returns the version for the cookie. 0 means original Netscape cookie and 1 means RFC 2109 compliant cookie.

Returns:

the version for the cookie.


isHttpOnly

isHttpOnly() : boolean

Identifies if the cookie is http-only.

Returns:

true if the cookie is http-only, false otherwise.


setComment

setComment(comment : String) : void

Sets the comment associated with the cookie. Setting a comment automatically changes the cookie to be a RFC 2109 (set-cookie2) compliant cookie, because comments are only supported with RFC cookies and not with Netscapes original cookie.

Parameters:

comment - the comment associated with the cookie.


setDomain

setDomain(domain : String) : void

Sets the domain associated with the cookie.

Parameters:

domain - the comment associated with the cookie.


setHttpOnly

setHttpOnly(httpOnly : boolean) : void

Sets the http-only state for the cookie.

Parameters:

httpOnly - sets http-only state for the cookie.


setMaxAge

setMaxAge(age : Number) : void

Sets the maximum age of the cookie in seconds. A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age. A negative value means that the cookie is not stored persistently and will be deleted when the client exits. A zero value causes the cookie to be deleted.

Parameters:

age - an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookie


setPath

setPath(path : String) : void

Sets the path for the cookie.

Parameters:

path - the path for the cookie.


setSecure

setSecure(secure : boolean) : void

Sets the secure state for the cookie.

Parameters:

secure - sets secure state for the cookie.


setValue

setValue(value : String) : void

Sets the cookie's value.

Parameters:

value - the value to set in the cookie.


setVersion

setVersion(version : Number) : void

Sets the version for the cookie. 0 means original Netscape cookie and 1 means RFC 2109 compliant cookie. The default is 0.

Parameters:

version - the version for the cookie.