{"name":"set-cookie-parser","version":"2.5.0","description":"Parses set-cookie headers into objects","homepage":"https://github.com/nfriedly/set-cookie-parser","repository":{"type":"git","url":"git+https://github.com/nfriedly/set-cookie-parser.git"},"author":{"name":"Nathan Friedly","url":"http://nfriedly.com/"},"main":"./lib/set-cookie.js","sideEffects":false,"keywords":["set-cookie","set","cookie","cookies","header","parser"],"devDependencies":{"eslint":"^8.17.0","eslint-config-prettier":"^6.10.1","eslint-plugin-prettier":"^3.1.2","husky":"^4.2.3","mocha":"^10.0.0","prettier":"^2.0.2","pretty-quick":"^2.0.1","sinon":"^9.0.1"},"scripts":{"lint":"eslint . --ignore-pattern '!.eslintrc.js'","test":"npm run lint && mocha","autofix":"npm run lint -- --fix","precommit":"npm test"},"license":"MIT","dependencies":{},"gitHead":"6687aa0b4eb0a381dd31d1611dc0e89271e3ca77","bugs":{"url":"https://github.com/nfriedly/set-cookie-parser/issues"},"_id":"set-cookie-parser@2.5.0","_nodeVersion":"10.19.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-cHMAtSXilfyBePduZEBVPTCftTQWz6ehWJD5YNUg4mqvRosrrjKbo4WS8JkB0/RxonMoohHm7cOGH60mDkRQ9w==","shasum":"96b59525e1362c94335c3c761100bb6e8f2da4b0","tarball":"http://registry-npm.ywwl.com/set-cookie-parser/download/set-cookie-parser-2.5.0.tgz","fileCount":4,"unpackedSize":14505,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDvBh6fTEywVCheHTZfriVNLrXw3WOIEukYEbHTx4AYDgIgS3AJ16mN4978PMYs19YXpGFWdnHEe5JVVMV3kGsTNgc="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJim1zaACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpKew/5ATS9iJe7XlAnxt97Lw41NGHHxu9lwIemRMa2vTBNVw2/8eGj\r\ntQJoPFLFisyJucnUGe02p7UtUKiHYzEDZDPLB5ngM58ZbG/m804gFr6z24qj\r\nm81O2IPvQWbnSrbnddpf/enS2n/YjgMM7k+orKZFB6ZBH0JurYcE1ydYsPRB\r\nzGT+mjBszeSAgKAJh8Lzv2u60sgoRAH88dvgvWvfVj3mdvFvLXGjMsSv5iVo\r\n3syB1idkexdhoAIrlwXoMZ9CKOe8UYuQT5QWv1Ec2Mbckq1yqvvaeys/PaCy\r\nZe1rVrTRMy9FGNl4jUt1gHyYEim8WFJIuxhOIdOohFzjKlSFgZBgRhCOIPPA\r\ncxN2DJEttfQ+IefXzI2+a5/QCLLUIyKcVzfe29lm33XWzV+VmdmdUHap+Swi\r\n0hbDkMu38mCyCeadcAC/m16FktSgIdmZpK6fZVHHkoKmOK2lhnJFyLDqCagq\r\ne6ZlWF7Cie1sJR0wFcPFuEvNwOljJhKBNQQEwMe4bXTdIZxSEOg+BJV9XqxA\r\n0xkrnncHEYu2nipCMWmZ8fj6MjqoEsOyAj0Q72oYA5ZMKQoSEpvKJexps9jr\r\nfj2cZij5jTF6tW28+CltpjVKiMPEUcZeyrqHgGZAo+NC84viUTpYOzFwwkD7\r\ntOR9sj9yFdULZPpg/3wUYdjxrppQcZooaqk=\r\n=HOfM\r\n-----END PGP SIGNATURE-----\r\n","size":5514,"noattachment":false,"key":"/set-cookie-parser/-/set-cookie-parser-2.5.0.tgz"},"_npmUser":{"name":"nfriedly","email":"nathan@nfriedly.com"},"directories":{},"maintainers":[{"name":"nfriedly","email":"nathan@nfriedly.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/set-cookie-parser_2.5.0_1654349018243_0.27713576333666645"},"_hasShrinkwrap":false,"readme":"# set-cookie-parser \r\n\r\n[![Node.js CI](https://github.com/nfriedly/set-cookie-parser/actions/workflows/node.js.yml/badge.svg)](https://github.com/nfriedly/set-cookie-parser/actions/workflows/node.js.yml)\r\n[![NPM version][npm-image]][npm-url] \r\n[![npm downloads](https://img.shields.io/npm/dm/set-cookie-parser)][npm-url]\r\n\r\nParses set-cookie headers into objects\r\n\r\nAccepts a single `set-cookie` header value, an array of `set-cookie` header values, a Node.js response object, or a `fetch()` `Response` object that may have 0 or more `set-cookie` headers.\r\n\r\nAlso accepts an optional options object. Defaults:\r\n\r\n```js\r\n{\r\n    decodeValues: true,  // Calls decodeURIComponent on each value - default: true\r\n    map: false,          // Return an object instead of an array - default: false\r\n    silent: false,       // Suppress the warning that is logged when called on a request instead of a response - default: false\r\n}\r\n```\r\n\r\nReturns either an array of cookie objects or a map of name => cookie object with `{map: true}`. Each cookie object will have, at a minimum `name` and `value` properties, and may have additional properties depending on the set-cookie header:\r\n\r\n* `name` - cookie name (string)\r\n* `value` - cookie value (string)\r\n* `path` - cookie path (string or undefined)\r\n* `domain` - domain for the cookie (string or undefined, may begin with \".\" to indicate the named domain or any subdomain of it)\r\n* `expires` - absolute expiration date for the cookie (Date object or undefined)\r\n* `maxAge` - relative max age of the cookie in seconds from when the client receives it (integer or undefined)\r\n  * Note: when using with [express's res.cookie() method](http://expressjs.com/en/4x/api.html#res.cookie), multiply `maxAge` by 1000 to convert to milliseconds.\r\n* `secure` - indicates that this cookie should only be sent over HTTPs (true or undefined)\r\n* `httpOnly` - indicates that this cookie should *not* be accessible to client-side JavaScript (true or undefined)\r\n* `sameSite` - indicates a cookie ought not to be sent along with cross-site requests (string or undefined)\r\n\r\n(The output format is loosely based on the input format of https://www.npmjs.com/package/cookie)\r\n\r\n## Install\r\n\r\n```sh\r\n$ npm install --save set-cookie-parser\r\n```\r\n\r\n\r\n## Usage\r\n\r\n### Get array of cookie objects\r\n\r\n```js\r\nvar http = require('http');\r\nvar setCookie = require('set-cookie-parser');\r\n\r\nhttp.get('http://example.com', function(res) {\r\n  var cookies = setCookie.parse(res, {\r\n    decodeValues: true  // default: true\r\n  });\r\n\r\n  cookies.forEach(console.log);\r\n}\r\n```\r\n\r\nExample output:\r\n\r\n```js\r\n[\r\n    {\r\n        name: 'bam',\r\n        value: 'baz'\r\n    },\r\n    {\r\n        name: 'foo',\r\n        value: 'bar',\r\n        path: '/',\r\n        expires: new Date('Tue Jul 01 2025 06:01:11 GMT-0400 (EDT)'),\r\n        maxAge: 1000,\r\n        domain: '.example.com',\r\n        secure: true,\r\n        httpOnly: true,\r\n        sameSite: 'lax'\r\n    }\r\n]\r\n```\r\n\r\n### Get map of cookie objects\r\n\r\n```js\r\nvar http = require('http');\r\nvar setCookie = require('set-cookie-parser');\r\n\r\nhttp.get('http://example.com', function(res) {\r\n  var cookies = setCookie.parse(res, {\r\n    decodeValues: true,  // default: true\r\n    map: true            // default: false\r\n  });\r\n\r\n  var desiredCookie = cookies['session'];\r\n  console.log(desiredCookie);\r\n});\r\n```\r\nExample output:\r\n```js\r\n{\r\n    bam: {\r\n        name: 'bam',\r\n        value: 'baz'\r\n    },\r\n    foo: {\r\n        name: 'foo',\r\n        value: 'bar',\r\n        path: '/',\r\n        expires: new Date('Tue Jul 01 2025 06:01:11 GMT-0400 (EDT)'),\r\n        maxAge: 1000,\r\n        domain: '.example.com',\r\n        secure: true,\r\n        httpOnly: true,\r\n        sameSite: 'lax'\r\n    }\r\n}\r\n```\r\n\r\n### Creating a new, modified set-cookie header\r\n\r\nThis library can be used in conjunction with the [cookie](https://www.npmjs.com/package/cookie) library to modify and replace set-cookie headers:\r\n\r\n```js\r\nconst libCookie = require('cookie');\r\nconst setCookie = require('set-cookie-parser');\r\n\r\nfunction modifySetCookie(res){\r\n  // parse the set-cookie headers with this library\r\n  let cookies = setCookie.parse(res);\r\n  \r\n  // modify the cookies here\r\n  // ...\r\n  \r\n  // create new set-cookie headers using the cookie library\r\n  res.headers['set-cookie'] = cookies.map(function(cookie) {\r\n      return libCookie.serialize(cookie.name, cookie.value, cookie);\r\n  });\r\n}\r\n```\r\n\r\nSee a real-world example of this in [unblocker](https://github.com/nfriedly/node-unblocker/blob/08a89ec27274b46dcd80d0a324a59406f2bdad3d/lib/cookies.js#L67-L85)\r\n\r\n## Usage in React Native (and with some other fetch implementations)\r\n\r\nReact Native follows the Fetch spec more closely and combines all of the Set-Cookie header values into a single string.\r\nThe `splitCookiesString` method reverses this.\r\n\r\n```js\r\nvar setCookie = require('set-cookie-parser');\r\n\r\nvar response = fetch(/*...*/);\r\n\r\n// This is mainly for React Native; Node.js does not combine set-cookie headers.\r\nvar combinedCookieHeader = response.headers.get('Set-Cookie');\r\nvar splitCookieHeaders = setCookie.splitCookiesString(combinedCookieHeader)\r\nvar cookies = setCookie.parse(splitCookieHeaders);\r\n\r\nconsole.log(cookies); // should be an array of cookies\r\n```\r\n\r\nThis behavior may become a default part of parse in the next major release, but requires the extra step for now.\r\n\r\nNote that the `fetch()` spec now includes a `getSetCookie()` method that provides un-combined `Set-Cookie` headers. This library will automatically use that method if it is present.\r\n\r\n## API\r\n\r\n### parse(input, [options])\r\n\r\nParses cookies from a string, array of strings, or a http response object. \r\nAlways returns an array, regardless of input format. (Unless the `map` option is set, in which case it always returns an object.)\r\n\r\n### parseString(individualSetCookieHeader, [options])\r\n\r\nParses a single set-cookie header value string. Options default is `{decodeValues: true}`. Used under-the-hood by `parse()`. \r\nReturns an object.\r\n\r\n### splitCookiesString(combinedSetCookieHeader)\r\n\r\nIt's uncommon, but the HTTP spec does allow for multiple of the same header to have their values combined (comma-separated) into a single header. \r\nThis method splits apart a combined header without choking on commas that appear within a cookie's value (or expiration date).\r\nReturns an array of strings that may be passed to `parse()`.\r\n\r\n## V2 Changes\r\n\r\n* Added decodeValues option (calls `decodeURIComponent()` on each cookie value), enabled by default.\r\n* Added `splitCookiesString` method.\r\n\r\n## References\r\n\r\n* [RFC 6265: HTTP State Management Mechanism](https://tools.ietf.org/html/rfc6265)\r\n* [draft-ietf-httpbis-rfc6265bis-10](https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html)\r\n\r\n## License\r\n\r\nMIT © [Nathan Friedly](http://www.nfriedly.com/)\r\n\r\n\r\n[npm-image]: https://badge.fury.io/js/set-cookie-parser.svg\r\n[npm-url]: https://npmjs.org/package/set-cookie-parser\r\n","publish_time":1654349018432,"_cnpm_publish_time":1654349018432,"dist-tags":{"backports":"2.7.3","latest":"4.0.0"}}