@3846masa/axios-cookiejar-support
Advanced tools
Comparing version 0.1.0 to 0.1.1
'use strict'; | ||
const pify = require('pify'); | ||
function requestInterceptorResolve (config) { | ||
@@ -31,9 +33,15 @@ return Promise.resolve(config) | ||
if (local.jar && config.withCredentials) { | ||
const cookieString = local.jar.getCookieStringSync(config.url); | ||
if (cookieString) { | ||
config.headers['Cookie'] = | ||
(config.headers['Cookie']) | ||
? cookieString + '; ' + config.headers['Cookie'] | ||
: cookieString; | ||
} | ||
const getCookieString = | ||
pify(local.jar.getCookieString.bind(local.jar)); | ||
return getCookieString(config.url) | ||
.then(function (cookieString) { | ||
if (!cookieString) { | ||
return; | ||
} | ||
config.headers['Cookie'] = | ||
(config.headers['Cookie']) | ||
? cookieString + '; ' + config.headers['Cookie'] | ||
: cookieString; | ||
}).then(function () { return config; }); | ||
} | ||
@@ -40,0 +48,0 @@ |
@@ -5,2 +5,3 @@ 'use strict'; | ||
const settle = require('axios/lib/core/settle'); | ||
const pify = require('pify'); | ||
@@ -12,2 +13,3 @@ function responseInterceptorResolve (response, instance) { | ||
const local = config._COOKIEJAR_SUPPORT_LOCAL; | ||
if (!local.jar || !response.headers['set-cookie']) { | ||
@@ -17,13 +19,17 @@ return response; | ||
const setCookie = pify(local.jar.setCookie.bind(local.jar)); | ||
const setCookiePromiseList = []; | ||
if (Array.isArray(response.headers['set-cookie'])) { | ||
const cookies = response.headers['set-cookie']; | ||
cookies.forEach(function (cookie) { | ||
local.jar.setCookieSync(cookie, config.url); | ||
setCookiePromiseList.push(setCookie(cookie, config.url)); | ||
}); | ||
} else { | ||
const cookie = response.headers['set-cookie']; | ||
local.jar.setCookieSync(cookie, config.url); | ||
setCookiePromiseList.push(setCookie(cookie, config.url)); | ||
} | ||
return response; | ||
return Promise.all(setCookiePromiseList) | ||
.then(function () { return response; }); | ||
}) | ||
@@ -30,0 +36,0 @@ .then(function redirectSetup (response) { |
{ | ||
"name": "@3846masa/axios-cookiejar-support", | ||
"description": "Add tough-cookie support to axios.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": "3846masa", | ||
@@ -14,2 +14,3 @@ "browser": { | ||
"@types/tough-cookie": "^2.3.1", | ||
"pify": "3.0.0", | ||
"tough-cookie": "2.3.2" | ||
@@ -16,0 +17,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29593
611
4
+ Addedpify@3.0.0
+ Addedpify@3.0.0(transitive)