allow cookieJars to be null in fetch wrapper

version bump
This commit is contained in:
jkhsjdhjs 2019-07-22 13:52:54 +02:00
parent 2add63a071
commit 83a640e9fb
Signed by: jkhsjdhjs
GPG Key ID: BAC6ADBAB7D576CC
3 changed files with 19 additions and 17 deletions

2
package-lock.json generated
View File

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

View File

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

View File

@ -4,6 +4,7 @@ import Cookie from "./cookie";
async function cookieFetch(cookieJars, url, options) {
let cookies = "";
if(cookieJars) {
if(Array.isArray(cookieJars) && cookieJars.every(c => c instanceof CookieJar)) {
cookieJars.forEach(jar => {
if(!jar.flags.includes("r"))
@ -21,7 +22,8 @@ async function cookieFetch(cookieJars, url, options) {
});
}
else
throw new TypeError("Third paramter is neither a cookie jar nor an array of cookie jars!");
throw new TypeError("First paramter is neither a cookie jar nor an array of cookie jars!");
}
if(cookies.length !== 0) {
if(!options) {
options = {
@ -35,7 +37,7 @@ async function cookieFetch(cookieJars, url, options) {
const result = await fetch(url, options);
// i cannot use headers.get() here because it joins the cookies to a string
cookies = result.headers[Object.getOwnPropertySymbols(result.headers)[0]]["set-cookie"];
if(cookies) {
if(cookies && cookieJars) {
if(Array.isArray(cookieJars)) {
cookieJars.forEach(jar => {
if(!jar.flags.includes("w"))