From f613a8c32e3d2588211657c9e7eab4166263305a Mon Sep 17 00:00:00 2001 From: jkhsjdhjs Date: Wed, 14 Aug 2019 00:38:11 +0200 Subject: [PATCH] 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 --- package-lock.json | 2 +- package.json | 2 +- src/index.mjs | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index afb6c75..80cf5db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "node-fetch-cookies", - "version": "1.1.0", + "version": "1.1.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a7cb486..860a563 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/index.mjs b/src/index.mjs index c339f0c..fe56b98 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -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)) {