axios-cookiejar-support
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -18,58 +18,8 @@ "use strict"; | ||
Function.prototype.$asyncspawn = function $asyncspawn(promiseProvider, self) { | ||
if (!Function.prototype.$asyncspawn) { | ||
Object.defineProperty(Function.prototype, "$asyncspawn", { | ||
value: $asyncspawn, | ||
enumerable: false, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} | ||
if (!(this instanceof Function)) return; | ||
var genF = this; | ||
return new promiseProvider(function enough(resolve, reject) { | ||
var gen = genF.call(self, resolve, reject); | ||
function step(fn, arg) { | ||
var next; | ||
try { | ||
next = fn.call(gen, arg); | ||
if (next.done) { | ||
if (next.value !== resolve) { | ||
if (next.value && next.value === next.value.then) return next.value(resolve, reject); | ||
resolve && resolve(next.value); | ||
resolve = null; | ||
} | ||
return; | ||
} | ||
if (next.value.then) { | ||
next.value.then(function (v) { | ||
step(gen.next, v); | ||
}, function (e) { | ||
step(gen.throw, e); | ||
}); | ||
} else { | ||
step(gen.next, next.value); | ||
} | ||
} catch (e) { | ||
reject && reject(e); | ||
reject = null; | ||
return; | ||
} | ||
} | ||
step(gen.next); | ||
}); | ||
}; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function requestInterceptor(config, instance) { | ||
return function* ($return, $error) { | ||
const local = config[_symbol.COOKIEJAR_SUPPORT_LOCAL] || {}; | ||
return new Promise(function ($return, $error) { | ||
let local; | ||
local = config[_symbol.COOKIEJAR_SUPPORT_LOCAL] || {}; | ||
config[_symbol.COOKIEJAR_SUPPORT_LOCAL] = local; | ||
@@ -103,20 +53,34 @@ local.backupOptions = local.backupOptions || {}; | ||
if (local.jar && config.withCredentials) { | ||
const getCookieString = (0, _pify.default)(local.jar.getCookieString.bind(local.jar)); | ||
const requestUrl = config.baseURL && !(0, _isAbsoluteURL.default)(config.url) ? (0, _combineURLs.default)(config.baseURL, config.url) : config.url; | ||
const cookieString = yield getCookieString(requestUrl); | ||
let getCookieString, requestUrl, cookieString; | ||
getCookieString = (0, _pify.default)(local.jar.getCookieString.bind(local.jar)); | ||
requestUrl = config.baseURL && !(0, _isAbsoluteURL.default)(config.url) ? (0, _combineURLs.default)(config.baseURL, config.url) : config.url; | ||
return Promise.resolve(getCookieString(requestUrl)).then(function ($await_2) { | ||
try { | ||
cookieString = $await_2; | ||
if (cookieString) { | ||
if (config.headers) { | ||
const currentCookie = config.headers['Cookie']; | ||
config.headers['Cookie'] = [currentCookie, cookieString].filter(c => !!c).join(';\x20'); | ||
} else { | ||
config.headers = { | ||
'Cookie': cookieString | ||
}; | ||
if (cookieString) { | ||
if (config.headers) { | ||
let currentCookie; | ||
currentCookie = config.headers['Cookie']; | ||
config.headers['Cookie'] = [currentCookie, cookieString].filter(c => !!c).join(';\x20'); | ||
} else { | ||
config.headers = { | ||
'Cookie': cookieString | ||
}; | ||
} | ||
} | ||
return $If_1.call(this); | ||
} catch ($boundEx) { | ||
return $error($boundEx); | ||
} | ||
} | ||
}.bind(this), $error); | ||
} | ||
return config; | ||
}.$asyncspawn(Promise, this); | ||
function $If_1() { | ||
return $return(config); | ||
} | ||
return $If_1.call(this); | ||
}); | ||
} | ||
@@ -123,0 +87,0 @@ |
@@ -18,69 +18,18 @@ "use strict"; | ||
Function.prototype.$asyncspawn = function $asyncspawn(promiseProvider, self) { | ||
if (!Function.prototype.$asyncspawn) { | ||
Object.defineProperty(Function.prototype, "$asyncspawn", { | ||
value: $asyncspawn, | ||
enumerable: false, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} | ||
if (!(this instanceof Function)) return; | ||
var genF = this; | ||
return new promiseProvider(function enough(resolve, reject) { | ||
var gen = genF.call(self, resolve, reject); | ||
function step(fn, arg) { | ||
var next; | ||
try { | ||
next = fn.call(gen, arg); | ||
if (next.done) { | ||
if (next.value !== resolve) { | ||
if (next.value && next.value === next.value.then) return next.value(resolve, reject); | ||
resolve && resolve(next.value); | ||
resolve = null; | ||
} | ||
return; | ||
} | ||
if (next.value.then) { | ||
next.value.then(function (v) { | ||
step(gen.next, v); | ||
}, function (e) { | ||
step(gen.throw, e); | ||
}); | ||
} else { | ||
step(gen.next, next.value); | ||
} | ||
} catch (e) { | ||
reject && reject(e); | ||
reject = null; | ||
return; | ||
} | ||
} | ||
step(gen.next); | ||
}); | ||
}; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function responseInterceptor(response, instance) { | ||
return function* ($return, $error) { | ||
// Set Cookies | ||
const config = response.config; | ||
const headers = response.headers; | ||
const statusCode = response.status; | ||
const local = config[_symbol.COOKIEJAR_SUPPORT_LOCAL]; | ||
return new Promise(function ($return, $error) { | ||
var config, headers, statusCode, local, setCookie, setCookiePromiseList, cookies, cookie; | ||
config = response.config; | ||
headers = response.headers; | ||
statusCode = response.status; | ||
local = config[_symbol.COOKIEJAR_SUPPORT_LOCAL]; | ||
if (local.jar && headers['set-cookie']) { | ||
const setCookie = (0, _pify.default)(local.jar.setCookie.bind(local.jar)); | ||
const setCookiePromiseList = []; | ||
setCookie = (0, _pify.default)(local.jar.setCookie.bind(local.jar)); | ||
setCookiePromiseList = []; | ||
if (Array.isArray(headers['set-cookie'])) { | ||
const cookies = headers['set-cookie']; | ||
cookies = headers['set-cookie']; | ||
cookies.forEach(function (cookie) { | ||
@@ -90,44 +39,59 @@ setCookiePromiseList.push(setCookie(cookie, config.url)); | ||
} else { | ||
const cookie = headers['set-cookie']; | ||
cookie = headers['set-cookie']; | ||
setCookiePromiseList.push(setCookie(cookie, config.url)); | ||
} | ||
yield Promise.all(setCookiePromiseList); | ||
return Promise.resolve(Promise.all(setCookiePromiseList)).then(function ($await_2) { | ||
try { | ||
return $If_1.call(this); | ||
} catch ($boundEx) { | ||
return $error($boundEx); | ||
} | ||
}.bind(this), $error); | ||
} // Redirect | ||
Object.assign(local.backupOptions, config, local.backupOptions); | ||
delete config.baseURL; | ||
config.url = _url.default.resolve(config.url, headers['location'] || ''); | ||
local.redirectCount--; | ||
function $If_1() { | ||
Object.assign(local.backupOptions, config, local.backupOptions); | ||
delete config.baseURL; | ||
config.url = _url.default.resolve(config.url, headers['location'] || ''); | ||
local.redirectCount--; | ||
if (local.redirectCount >= 0 && (0, _isRedirect.default)(statusCode) && !!headers['location']) { | ||
if (response.status !== 307) { | ||
config.method = 'get'; | ||
} | ||
if (local.redirectCount >= 0 && (0, _isRedirect.default)(statusCode) && !!headers['location']) { | ||
if (response.status !== 307) { | ||
config.method = 'get'; | ||
} | ||
config.maxRedirects = local.redirectCount; | ||
return instance.request(config); | ||
} // Restore | ||
config.maxRedirects = local.redirectCount; | ||
return $return(instance.request(config)); | ||
} // Restore | ||
if (local) { | ||
Object.assign(config, local.backupOptions); | ||
} | ||
if (local) { | ||
Object.assign(config, local.backupOptions); | ||
} | ||
if (local && local.jar) { | ||
if (instance.defaults.jar && (!config.jar || config.jar === true)) { | ||
instance.defaults.jar = local.jar; | ||
if (local && local.jar) { | ||
if (instance.defaults.jar && (!config.jar || config.jar === true)) { | ||
instance.defaults.jar = local.jar; | ||
} | ||
config.jar = local.jar; | ||
} | ||
config.jar = local.jar; | ||
delete config[_symbol.COOKIEJAR_SUPPORT_LOCAL]; // Validate | ||
return Promise.resolve(new Promise(function (resolve, reject) { | ||
(0, _settle.default)(resolve, reject, response); | ||
})).then(function ($await_3) { | ||
try { | ||
return $return(response); | ||
} catch ($boundEx) { | ||
return $error($boundEx); | ||
} | ||
}, $error); | ||
} | ||
delete config[_symbol.COOKIEJAR_SUPPORT_LOCAL]; // Validate | ||
yield new Promise(function (resolve, reject) { | ||
(0, _settle.default)(resolve, reject, response); | ||
}); | ||
return response; | ||
}.$asyncspawn(Promise, this); | ||
return $If_1.call(this); | ||
}); | ||
} | ||
@@ -134,0 +98,0 @@ |
@@ -14,3 +14,3 @@ { | ||
}, | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"main": "./lib/index", | ||
@@ -43,3 +43,3 @@ "directories": { | ||
"eslint": "5.4.0", | ||
"fast-async": "6.3.7", | ||
"fast-async": "7.0.6", | ||
"intelli-espower-loader": "1.0.1", | ||
@@ -46,0 +46,0 @@ "mocha": "5.2.0", |
Sorry, the diff of this file is not supported yet
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
127450
862