allow cookieJars to be null in fetch wrapper
version bump
This commit is contained in:
parent
2add63a071
commit
83a640e9fb
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "node-fetch-cookies",
|
"name": "node-fetch-cookies",
|
||||||
"version": "1.0.3",
|
"version": "1.0.5",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "node-fetch-cookies",
|
"name": "node-fetch-cookies",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"description": "node-fetch wrapper that adds support for cookie-jars",
|
"description": "node-fetch wrapper that adds support for cookie-jars",
|
||||||
"main": "src/index.mjs",
|
"main": "src/index.mjs",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
|
@ -4,24 +4,26 @@ import Cookie from "./cookie";
|
||||||
|
|
||||||
async function cookieFetch(cookieJars, url, options) {
|
async function cookieFetch(cookieJars, url, options) {
|
||||||
let cookies = "";
|
let cookies = "";
|
||||||
if(Array.isArray(cookieJars) && cookieJars.every(c => c instanceof CookieJar)) {
|
if(cookieJars) {
|
||||||
cookieJars.forEach(jar => {
|
if(Array.isArray(cookieJars) && cookieJars.every(c => c instanceof CookieJar)) {
|
||||||
if(!jar.flags.includes("r"))
|
cookieJars.forEach(jar => {
|
||||||
return;
|
if(!jar.flags.includes("r"))
|
||||||
jar.forEach(c => {
|
return;
|
||||||
|
jar.forEach(c => {
|
||||||
|
if(c.isValidForRequest(url))
|
||||||
|
cookies += c.serialize() + "; ";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if(cookieJars instanceof CookieJar && cookieJars.flags.includes("r")) {
|
||||||
|
cookieJars.forEach(c => {
|
||||||
if(c.isValidForRequest(url))
|
if(c.isValidForRequest(url))
|
||||||
cookies += c.serialize() + "; ";
|
cookies += c.serialize() + "; ";
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
else
|
||||||
|
throw new TypeError("First paramter is neither a cookie jar nor an array of cookie jars!");
|
||||||
}
|
}
|
||||||
else if(cookieJars instanceof CookieJar && cookieJars.flags.includes("r")) {
|
|
||||||
cookieJars.forEach(c => {
|
|
||||||
if(c.isValidForRequest(url))
|
|
||||||
cookies += c.serialize() + "; ";
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw new TypeError("Third paramter is neither a cookie jar nor an array of cookie jars!");
|
|
||||||
if(cookies.length !== 0) {
|
if(cookies.length !== 0) {
|
||||||
if(!options) {
|
if(!options) {
|
||||||
options = {
|
options = {
|
||||||
|
@ -35,7 +37,7 @@ async function cookieFetch(cookieJars, url, options) {
|
||||||
const result = await fetch(url, options);
|
const result = await fetch(url, options);
|
||||||
// i cannot use headers.get() here because it joins the cookies to a string
|
// i cannot use headers.get() here because it joins the cookies to a string
|
||||||
cookies = result.headers[Object.getOwnPropertySymbols(result.headers)[0]]["set-cookie"];
|
cookies = result.headers[Object.getOwnPropertySymbols(result.headers)[0]]["set-cookie"];
|
||||||
if(cookies) {
|
if(cookies && cookieJars) {
|
||||||
if(Array.isArray(cookieJars)) {
|
if(Array.isArray(cookieJars)) {
|
||||||
cookieJars.forEach(jar => {
|
cookieJars.forEach(jar => {
|
||||||
if(!jar.flags.includes("w"))
|
if(!jar.flags.includes("w"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user