filter cookies with same names before sending

duplicate names may occur if we store cookies with the same name for example.com with subdomains and for sub.example.com
This commit is contained in:
jkhsjdhjs 2019-08-14 00:38:11 +02:00
parent 14a874f208
commit f613a8c32e
Signed by: jkhsjdhjs
GPG Key ID: BAC6ADBAB7D576CC
3 changed files with 3 additions and 2 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "node-fetch-cookies",
"version": "1.1.0",
"version": "1.1.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "node-fetch-cookies",
"version": "1.1.0",
"version": "1.1.1",
"description": "node-fetch wrapper that adds support for cookie-jars",
"main": "src/index.mjs",
"engines": {

View File

@ -16,6 +16,7 @@ async function cookieFetch(cookieJars, url, options) {
domains
.map(d => [...jar.iterValidForRequest(d, url)])
.reduce((a, b) => [...a, ...b])
.filter((v, i, a) => a.slice(0, i).every(c => c.name !== v.name)) //unique
.forEach(c => cookies += c.serialize() + "; ");
if(cookieJars) {
if(Array.isArray(cookieJars) && cookieJars.every(c => c instanceof CookieJar)) {