Skip to content

Commit 73af733

Browse files
committed
fix: delete cookie header to avoid duplicates of cookies
1 parent dc4f36e commit 73af733

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/index.mjs

+6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ async function fetch(cookieJars, url, options) {
5555
// or, if headers is an object, construct a Headers object from it
5656
options.headers = new Headers(options.headers);
5757
if (cookies) {
58+
if (options.headers.has("cookie"))
59+
throw new Error(
60+
"options.headers already contains a cookie header!"
61+
);
5862
options.headers.append("cookie", cookies.slice(0, -2));
5963
}
6064
if (wantFollow) options.redirect = "manual";
@@ -93,6 +97,8 @@ async function fetch(cookieJars, url, options) {
9397
}
9498
const location = result.headers.get("location");
9599
options.redirect = "follow";
100+
// delete cookie header from previous request to avoid a duplicate cookie header
101+
options.headers.delete("cookie");
96102
return fetch(cookieJars, location, options);
97103
}
98104
return result;

0 commit comments

Comments
 (0)