Cookie

Cookie

A Postman Cookie definition that comprehensively represents an HTTP Cookie.

Parameters:
Name Type Attributes Description
options Cookie.definition <optional>

Pass the initial definition of the Cookie.

Source:
Examples

Create a new Cookie

var Cookie = require('postman-collection').Cookie,
    myCookie = new Cookie({
         name: 'my-cookie-name',
         expires: '1464769543832', // UNIX timestamp, in *milliseconds*
         maxAge: '300',  // In seconds. In this case, the Cookie is valid for 5 minutes
         domain: 'something.example.com',
         path: '/',
         secure: false,
         httpOnly: true,
         session: false,
         value: 'my-cookie-value',
         extensions: [{
             key: 'Priority',
             value: 'HIGH'
         }]
    });

Parse a Cookie Header

var Cookie = require('postman-collection').Cookie,
    rawHeader = 'myCookie=myValue;Path=/;Expires=Sun, 04-Feb-2018 14:18:27 GMT;Secure;HttpOnly;Priority=HIGH'
    myCookie = new Cookie(rawHeader);

console.log(myCookie.toJSON());

Extends

Members

domain :String

Indicates the domain(s) for which the cookie should be sent.

Type:
  • String
Source:

expires :Date|String

Expires sets an expiry date for when a cookie gets deleted. It should either be a date object or timestamp string of date.

Type:
  • Date | String
Source:
To Do:
  • Accept date object and convert stringified date (timestamp only) to date object
  • Consider using Infinity as a default

extensions :Array

Any extra parameters that are not strictly a part of the Cookie spec go here.

Type:
  • Array
Source:

hostOnly :Boolean

Type:
  • Boolean
Source:

httpOnly :Boolean

The idea behind HTTP-only cookies is to instruct a browser that a cookie should never be accessible via JavaScript through the document.cookie property. This feature was designed as a security measure to help prevent cross-site scripting (XSS) attacks perpetrated by stealing cookies via JavaScript.

Type:
  • Boolean
Source:

maxAge :Number

Max-age sets the time in seconds for when a cookie will be deleted.

Type:
  • Number
Source:

name :String

The name of the cookie.

Type:
  • String
Source:

path :String

Type:
  • String
Source:

secure :Boolean

A secure cookie will only be sent to the server when a request is made using SSL and the HTTPS protocol. The idea that the contents of the cookie are of high value and could be potentially damaging to transmit as clear text.

Type:
  • Boolean
Source:

session :Boolean

Indicates whether this is a Session Cookie.

Type:
  • Boolean
Source:

value :String

Type:
  • String
Source:

Methods

(static) isCookie(obj) → {Boolean}

Check whether an object is an instance of PostmanCookie.

Parameters:
Name Type Description
obj *
Source:
Returns:
Type
Boolean

(static) parse(str) → {*}

Cookie header parser

Parameters:
Name Type Description
str String
Source:
Returns:

A plain cookie options object, use it to create a new Cookie

Type
*

(static) stringify(cookie) → {String}

Converts the Cookie to a single Set-Cookie header string.

Parameters:
Name Type Description
cookie Cookie

Cookie definition object

Source:
Returns:
Type
String

(static) unparse(cookies) → {String}

Stringifies an Array or PropertyList of Cookies into a single string.

Parameters:
Name Type Description
cookies Array.<Cookie>

List of cookie definition object

Source:
Returns:
Type
String

(static) unparseSingle(cookie) → {String}

Unparses a single Cookie.

Parameters:
Name Type Description
cookie Cookie

Cookie definition object

Source:
Returns:
Type
String

findInParents(property, customizeropt) → {*|undefined}

Tries to find the given property locally, and then proceeds to lookup in each parent, going up the chain as necessary. Lookup will continue until customizer returns a truthy value. If used without a customizer, the lookup will stop at the first parent that contains the property.

Parameters:
Name Type Attributes Description
property String
customizer function <optional>
Inherited From:
Source:
Returns:
Type
* | undefined

forEachParent(options, iterator)

Invokes the given iterator for every parent in the parent chain of the given element.

Parameters:
Name Type Description
options Object

A set of options for the parent chain traversal.

Properties
Name Type Attributes Default Description
withRoot Boolean <optional>
<nullable>
false

Set to true to include the collection object as well.

iterator function

The function to call for every parent in the ancestry chain.

Inherited From:
Source:
To Do:
  • Cache the results

meta() → {*}

Returns the meta keys associated with the property

Inherited From:
Source:
Returns:
Type
*

parent() → {*|undefined}

Returns the parent of item

Inherited From:
Source:
Returns:
Type
* | undefined

toJSON()

Returns the JSON representation of a property, which conforms to the way it is defined in a collection. You can use this method to get the instantaneous representation of any property, including a Collection.

Inherited From:
Source:

toString() → {String}

Converts the Cookie to a single Set-Cookie header string.

Source:
Returns:
Type
String

valueOf() → {String}

Get the value of this cookie.

Source:
Returns:
Type
String

Type Definitions

definition

The following is the object structure accepted as constructor parameter while calling new Cookie(...). It is also the structure exported when Property#toJSON or Property#toObjectResolved is called on a Cookie instance.

Properties:
Name Type Attributes Description
key String <optional>

The name of the cookie. Some call it the "name".

value String <optional>

The value stored in the Cookie

expires String <optional>

Expires sets an expiry date for when a cookie gets deleted. It should either be a date object or timestamp string of date.

maxAge Number <optional>

Max-age sets the time in seconds for when a cookie will be deleted.

domain String <optional>

Indicates the domain(s) for which the cookie should be sent.

path String <optional>

Limits the scope of the cookie to a specified path, e.g: "/accounts"

secure Boolean <optional>

A secure cookie will only be sent to the server when a request is made using SSL and the HTTPS protocol. The idea that the contents of the cookie are of high value and could be potentially damaging to transmit as clear text.

httpOnly Boolean <optional>

The idea behind HTTP-only cookies is to instruct a browser that a cookie should never be accessible via JavaScript through the document.cookie property. This feature was designed as a security measure to help prevent cross-site scripting (XSS) attacks perpetrated by stealing cookies via JavaScript.

hostOnly Boolean <optional>

Indicates that this cookie is only valid for the given domain (and not its parent or child domains.)

session Boolean <optional>

Indicates whether this is a Session Cookie. (A transient cookie, which is deleted at the end of an HTTP session.)

extensions Array <optional>

Any extra attributes that are extensions to the original Cookie specification can be specified here.

extensions[].key String <optional>

Name of the extension.

extensions[].value String <optional>

Value of the extension

Source:
Example

JSON definition of an example cookie

{
    "key": "my-cookie-name",
    "expires": "1464769543832",
     // UNIX timestamp, in *milliseconds*
    "maxAge": "300",
     // In seconds. In this case, the Cookie is valid for 5 minutes
    "domain": "something.example.com",
    "path": "/",
    "secure": false,
    "httpOnly": true,
    "session": false,
    "value": "my-cookie-value",
    "extensions": [{
        "key": "Priority",
        "value": "HIGH"
    }]
}