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109](http://tools.ietf.org/html/rfc2109.html) and\n// [document.cookie](http://dev/loper.mozilla.org/en/document.cookie)\nconst DOM         = require('./dom');\nconst { isArray } = require('util');\nconst Tough       = require('tough-cookie');\nconst { Cookie }  = Tough;\n\n\n// Lists all available cookies.\nmodule.exports = class Cookies extends Array {\n\n  constructor() {\n    super();\n  }\n\n  // Used to dump state to console (debugging)\n  dump(output = process.stdout) {\n    for (let cookie of this.sort(Tough.cookieCompare))\n      output.write(`${cookie}\\n`);\n  }\n\n  // Serializes all selected cookies into a single string.  Used to generate a cookies header.\n  //\n  // domain - Request hostname\n  // path   - Request pathname\n  serialize(domain, path) {\n    return this\n      .select({ domain: domain, path: path })\n      .map(cookie => cookie.cookieString())\n      .join('; ');\n  }\n\n  // Returns all cookies that match the identifier (name, domain and path).\n  // This is used for retrieving cookies.\n  select(identifier) {\n    let cookies = this.filter(cookie => cookie.TTL() > 0); // eslint-disable-line new-cap\n    if (identifier.name)\n      cookies = cookies.filter(cookie => cookie.key === identifier.name);\n    if (identifier.path)\n      cookies = cookies.filter(cookie => Tough.pathMatch(identifier.path, cookie.path));\n    if (identifier.domain)\n      cookies = cookies.filter(cookie => Tough.domainMatch(identifier.domain, cookie.domain));\n    return cookies\n      .sort((a, b)=> b.domain.length - a.domain.length)\n      .sort(Tough.cookieCompare);\n  }\n\n  // Adds a new cookie, updates existing cookie (same name, domain and path), or\n  // deletes a cookie (if expires in the past).\n  set(params) {\n    const cookie = new Cookie({\n      key:    params.name,\n      value:  params.value,\n      domain: params.domain || 'localhost',\n      path:   params.path || '/'\n    });\n    if (params.expires)\n      cookie.setExpires(params.expires);\n    else if (params.hasOwnProperty('max-age'))\n      cookie.setMaxAge(params['max-age']);\n    cookie.secure   = !!params.secure;\n    cookie.httpOnly = !!params.httpOnly;\n\n    // Delete cookie before setting it, so we only store one cookie (per\n    // domain/path/name)\n    this\n      .filter(c   => c.domain === cookie.domain)\n      .filter(c   => c.path === cookie.path)\n      .filter(c   => c.key === cookie.key)\n      .forEach(c  => this.delete(c));\n    if (cookie.TTL() > 0) // eslint-disable-line new-cap\n      this.push(cookie);\n  }\n\n  // Delete the specified cookie.\n  delete(cookie) {\n    const index = this.indexOf(cookie);\n    if (~index)\n      this.splice(index, 1);\n  }\n\n  // Deletes all cookies.\n  deleteAll() {\n    this.length = 0;\n  }\n\n  // Update cookies with HTTP response\n  //\n  // httpHeader - Value of HTTP Set-Cookie header (string/array)\n  // domain     - Set from hostname\n  // path       - Set from pathname\n  update(httpHeader, domain, path) {\n    // One Set-Cookie is a string, multiple is an array\n    const headers = isArray(httpHeader) ? httpHeader : [httpHeader];\n    headers\n      .map(cookie => Cookie.parse(cookie))\n      .filter(cookie => cookie)\n      .forEach(cookie => {\n        cookie.domain = cookie.domain || domain;\n        cookie.path   = cookie.path || Tough.defaultPath(path);\n\n        // Delete cookie before setting it, so we only store one cookie (per\n        // domain/path/name)\n        this\n          .filter(c   => c.domain === cookie.domain)\n          .filter(c   => c.path === cookie.path)\n          .filter(c   => c.key === cookie.key)\n          .forEach(c  => this.delete(c));\n        if (cookie.TTL() > 0) // eslint-disable-line new-cap\n          this.push(cookie);\n      });\n  }\n\n};\n\n\n// Returns name=value pairs\nDOM.HTMLDocument.prototype.__defineGetter__('cookie', function() {\n  const { cookies } = this.defaultView.browser;\n  return cookies\n    .select({ domain: this.location.hostname, path: this.location.pathname })\n    .filter(cookie => !cookie.httpOnly)\n    .map(cookie    => `${cookie.key}=${cookie.value}`)\n    .join('; ');\n});\n\n// Accepts serialized form (same as Set-Cookie header) and updates cookie from\n// new values.\nDOM.HTMLDocument.prototype.__defineSetter__('cookie', function(cookie) {\n  const { cookies } = this.defaultView.browser;\n  cookies.update(cookie.toString(), this.location.hostname, this.location.pathname);\n});\n"]}