mirror of
https://github.com/tenrok/axios.git
synced 2026-06-05 16:42:32 +03:00
chore: release v1.2.0
This commit is contained in:
Vendored
+235
-177
@@ -1,4 +1,4 @@
|
||||
// Axios v1.1.3 Copyright (c) 2022 Matt Zabriskie and contributors
|
||||
// Axios v1.2.0 Copyright (c) 2022 Matt Zabriskie and contributors
|
||||
'use strict';
|
||||
|
||||
const FormData$1 = require('form-data');
|
||||
@@ -254,7 +254,7 @@ const trim = (str) => str.trim ?
|
||||
* @param {Function} fn The callback to invoke for each item
|
||||
*
|
||||
* @param {Boolean} [allOwnKeys = false]
|
||||
* @returns {void}
|
||||
* @returns {any}
|
||||
*/
|
||||
function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
||||
// Don't bother if no value provided
|
||||
@@ -289,6 +289,24 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
||||
}
|
||||
}
|
||||
|
||||
function findKey(obj, key) {
|
||||
key = key.toLowerCase();
|
||||
const keys = Object.keys(obj);
|
||||
let i = keys.length;
|
||||
let _key;
|
||||
while (i-- > 0) {
|
||||
_key = keys[i];
|
||||
if (key === _key.toLowerCase()) {
|
||||
return _key;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const _global = typeof self === "undefined" ? typeof global === "undefined" ? undefined : global : self;
|
||||
|
||||
const isContextDefined = (context) => !isUndefined(context) && context !== _global;
|
||||
|
||||
/**
|
||||
* Accepts varargs expecting each argument to be an object, then
|
||||
* immutably merges the properties of each object and returns result.
|
||||
@@ -308,16 +326,18 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
||||
* @returns {Object} Result of all merge properties
|
||||
*/
|
||||
function merge(/* obj1, obj2, obj3, ... */) {
|
||||
const {caseless} = isContextDefined(this) && this || {};
|
||||
const result = {};
|
||||
const assignValue = (val, key) => {
|
||||
if (isPlainObject(result[key]) && isPlainObject(val)) {
|
||||
result[key] = merge(result[key], val);
|
||||
const targetKey = caseless && findKey(result, key) || key;
|
||||
if (isPlainObject(result[targetKey]) && isPlainObject(val)) {
|
||||
result[targetKey] = merge(result[targetKey], val);
|
||||
} else if (isPlainObject(val)) {
|
||||
result[key] = merge({}, val);
|
||||
result[targetKey] = merge({}, val);
|
||||
} else if (isArray(val)) {
|
||||
result[key] = val.slice();
|
||||
result[targetKey] = val.slice();
|
||||
} else {
|
||||
result[key] = val;
|
||||
result[targetKey] = val;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -553,6 +573,11 @@ const reduceDescriptors = (obj, reducer) => {
|
||||
|
||||
const freezeMethods = (obj) => {
|
||||
reduceDescriptors(obj, (descriptor, name) => {
|
||||
// skip restricted props in strict mode
|
||||
if (isFunction(obj) && ['arguments', 'caller', 'callee'].indexOf(name) !== -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const value = obj[name];
|
||||
|
||||
if (!isFunction(value)) return;
|
||||
@@ -566,7 +591,7 @@ const freezeMethods = (obj) => {
|
||||
|
||||
if (!descriptor.set) {
|
||||
descriptor.set = () => {
|
||||
throw Error('Can not read-only method \'' + name + '\'');
|
||||
throw Error('Can not rewrite read-only method \'' + name + '\'');
|
||||
};
|
||||
}
|
||||
});
|
||||
@@ -635,7 +660,10 @@ const utils = {
|
||||
toObjectSet,
|
||||
toCamelCase,
|
||||
noop,
|
||||
toFiniteNumber
|
||||
toFiniteNumber,
|
||||
findKey,
|
||||
global: _global,
|
||||
isContextDefined
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1133,6 +1161,8 @@ class InterceptorManager {
|
||||
}
|
||||
}
|
||||
|
||||
const InterceptorManager$1 = InterceptorManager;
|
||||
|
||||
const transitionalDefaults = {
|
||||
silentJSONParsing: true,
|
||||
forcedJSONParsing: true,
|
||||
@@ -1320,7 +1350,7 @@ function buildFullPath(baseURL, requestedURL) {
|
||||
return requestedURL;
|
||||
}
|
||||
|
||||
const VERSION = "1.1.3";
|
||||
const VERSION = "1.2.0";
|
||||
|
||||
/**
|
||||
* A `CanceledError` is an object that is thrown when an operation is canceled.
|
||||
@@ -1447,7 +1477,6 @@ const parseHeaders = rawHeaders => {
|
||||
};
|
||||
|
||||
const $internals = Symbol('internals');
|
||||
const $defaults = Symbol('defaults');
|
||||
|
||||
function normalizeHeader(header) {
|
||||
return header && String(header).trim().toLowerCase();
|
||||
@@ -1473,6 +1502,10 @@ function parseTokens(str) {
|
||||
return tokens;
|
||||
}
|
||||
|
||||
function isValidHeaderName(str) {
|
||||
return /^[-_a-zA-Z]+$/.test(str.trim());
|
||||
}
|
||||
|
||||
function matchHeaderValue(context, value, header, filter) {
|
||||
if (utils.isFunction(filter)) {
|
||||
return filter.call(this, value, header);
|
||||
@@ -1509,27 +1542,12 @@ function buildAccessors(obj, header) {
|
||||
});
|
||||
}
|
||||
|
||||
function findKey(obj, key) {
|
||||
key = key.toLowerCase();
|
||||
const keys = Object.keys(obj);
|
||||
let i = keys.length;
|
||||
let _key;
|
||||
while (i-- > 0) {
|
||||
_key = keys[i];
|
||||
if (key === _key.toLowerCase()) {
|
||||
return _key;
|
||||
}
|
||||
class AxiosHeaders {
|
||||
constructor(headers) {
|
||||
headers && this.set(headers);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function AxiosHeaders(headers, defaults) {
|
||||
headers && this.set(headers);
|
||||
this[$defaults] = defaults || null;
|
||||
}
|
||||
|
||||
Object.assign(AxiosHeaders.prototype, {
|
||||
set: function(header, valueOrRewrite, rewrite) {
|
||||
set(header, valueOrRewrite, rewrite) {
|
||||
const self = this;
|
||||
|
||||
function setHeader(_value, _header, _rewrite) {
|
||||
@@ -1539,69 +1557,70 @@ Object.assign(AxiosHeaders.prototype, {
|
||||
throw new Error('header name must be a non-empty string');
|
||||
}
|
||||
|
||||
const key = findKey(self, lHeader);
|
||||
const key = utils.findKey(self, lHeader);
|
||||
|
||||
if (key && _rewrite !== true && (self[key] === false || _rewrite === false)) {
|
||||
return;
|
||||
if(!key || self[key] === undefined || _rewrite === true || (_rewrite === undefined && self[key] !== false)) {
|
||||
self[key || _header] = normalizeValue(_value);
|
||||
}
|
||||
|
||||
self[key || _header] = normalizeValue(_value);
|
||||
}
|
||||
|
||||
if (utils.isPlainObject(header)) {
|
||||
utils.forEach(header, (_value, _header) => {
|
||||
setHeader(_value, _header, valueOrRewrite);
|
||||
});
|
||||
const setHeaders = (headers, _rewrite) =>
|
||||
utils.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
|
||||
|
||||
if (utils.isPlainObject(header) || header instanceof this.constructor) {
|
||||
setHeaders(header, valueOrRewrite);
|
||||
} else if(utils.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
||||
setHeaders(parseHeaders(header), valueOrRewrite);
|
||||
} else {
|
||||
setHeader(valueOrRewrite, header, rewrite);
|
||||
header != null && setHeader(valueOrRewrite, header, rewrite);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
}
|
||||
|
||||
get: function(header, parser) {
|
||||
header = normalizeHeader(header);
|
||||
|
||||
if (!header) return undefined;
|
||||
|
||||
const key = findKey(this, header);
|
||||
|
||||
if (key) {
|
||||
const value = this[key];
|
||||
|
||||
if (!parser) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (parser === true) {
|
||||
return parseTokens(value);
|
||||
}
|
||||
|
||||
if (utils.isFunction(parser)) {
|
||||
return parser.call(this, value, key);
|
||||
}
|
||||
|
||||
if (utils.isRegExp(parser)) {
|
||||
return parser.exec(value);
|
||||
}
|
||||
|
||||
throw new TypeError('parser must be boolean|regexp|function');
|
||||
}
|
||||
},
|
||||
|
||||
has: function(header, matcher) {
|
||||
get(header, parser) {
|
||||
header = normalizeHeader(header);
|
||||
|
||||
if (header) {
|
||||
const key = findKey(this, header);
|
||||
const key = utils.findKey(this, header);
|
||||
|
||||
if (key) {
|
||||
const value = this[key];
|
||||
|
||||
if (!parser) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (parser === true) {
|
||||
return parseTokens(value);
|
||||
}
|
||||
|
||||
if (utils.isFunction(parser)) {
|
||||
return parser.call(this, value, key);
|
||||
}
|
||||
|
||||
if (utils.isRegExp(parser)) {
|
||||
return parser.exec(value);
|
||||
}
|
||||
|
||||
throw new TypeError('parser must be boolean|regexp|function');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
has(header, matcher) {
|
||||
header = normalizeHeader(header);
|
||||
|
||||
if (header) {
|
||||
const key = utils.findKey(this, header);
|
||||
|
||||
return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
}
|
||||
|
||||
delete: function(header, matcher) {
|
||||
delete(header, matcher) {
|
||||
const self = this;
|
||||
let deleted = false;
|
||||
|
||||
@@ -1609,7 +1628,7 @@ Object.assign(AxiosHeaders.prototype, {
|
||||
_header = normalizeHeader(_header);
|
||||
|
||||
if (_header) {
|
||||
const key = findKey(self, _header);
|
||||
const key = utils.findKey(self, _header);
|
||||
|
||||
if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
|
||||
delete self[key];
|
||||
@@ -1626,18 +1645,18 @@ Object.assign(AxiosHeaders.prototype, {
|
||||
}
|
||||
|
||||
return deleted;
|
||||
},
|
||||
}
|
||||
|
||||
clear: function() {
|
||||
clear() {
|
||||
return Object.keys(this).forEach(this.delete.bind(this));
|
||||
},
|
||||
}
|
||||
|
||||
normalize: function(format) {
|
||||
normalize(format) {
|
||||
const self = this;
|
||||
const headers = {};
|
||||
|
||||
utils.forEach(this, (value, header) => {
|
||||
const key = findKey(headers, header);
|
||||
const key = utils.findKey(headers, header);
|
||||
|
||||
if (key) {
|
||||
self[key] = normalizeValue(value);
|
||||
@@ -1657,30 +1676,47 @@ Object.assign(AxiosHeaders.prototype, {
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
}
|
||||
|
||||
toJSON: function(asStrings) {
|
||||
concat(...targets) {
|
||||
return this.constructor.concat(this, ...targets);
|
||||
}
|
||||
|
||||
toJSON(asStrings) {
|
||||
const obj = Object.create(null);
|
||||
|
||||
utils.forEach(Object.assign({}, this[$defaults] || null, this),
|
||||
(value, header) => {
|
||||
if (value == null || value === false) return;
|
||||
obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value;
|
||||
});
|
||||
utils.forEach(this, (value, header) => {
|
||||
value != null && value !== false && (obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value);
|
||||
});
|
||||
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
|
||||
Object.assign(AxiosHeaders, {
|
||||
from: function(thing) {
|
||||
if (utils.isString(thing)) {
|
||||
return new this(parseHeaders(thing));
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return Object.entries(this.toJSON())[Symbol.iterator]();
|
||||
}
|
||||
|
||||
toString() {
|
||||
return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
return 'AxiosHeaders';
|
||||
}
|
||||
|
||||
static from(thing) {
|
||||
return thing instanceof this ? thing : new this(thing);
|
||||
},
|
||||
}
|
||||
|
||||
accessor: function(header) {
|
||||
static concat(first, ...targets) {
|
||||
const computed = new this(first);
|
||||
|
||||
targets.forEach((target) => computed.set(target));
|
||||
|
||||
return computed;
|
||||
}
|
||||
|
||||
static accessor(header) {
|
||||
const internals = this[$internals] = (this[$internals] = {
|
||||
accessors: {}
|
||||
});
|
||||
@@ -1701,13 +1737,15 @@ Object.assign(AxiosHeaders, {
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
|
||||
|
||||
utils.freezeMethods(AxiosHeaders.prototype);
|
||||
utils.freezeMethods(AxiosHeaders);
|
||||
|
||||
const AxiosHeaders$1 = AxiosHeaders;
|
||||
|
||||
/**
|
||||
* Throttle decorator
|
||||
* @param {Function} fn
|
||||
@@ -1973,6 +2011,8 @@ class AxiosTransformStream extends stream__default["default"].Transform{
|
||||
}
|
||||
}
|
||||
|
||||
const AxiosTransformStream$1 = AxiosTransformStream;
|
||||
|
||||
const isBrotliSupported = utils.isFunction(zlib__default["default"].createBrotliDecompress);
|
||||
|
||||
const {http: httpFollow, https: httpsFollow} = followRedirects__default["default"];
|
||||
@@ -2156,7 +2196,7 @@ function httpAdapter(config) {
|
||||
data: convertedData,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {},
|
||||
headers: new AxiosHeaders$1(),
|
||||
config
|
||||
});
|
||||
}
|
||||
@@ -2169,7 +2209,7 @@ function httpAdapter(config) {
|
||||
));
|
||||
}
|
||||
|
||||
const headers = AxiosHeaders.from(config.headers).normalize();
|
||||
const headers = AxiosHeaders$1.from(config.headers).normalize();
|
||||
|
||||
// Set User-Agent (required by some servers)
|
||||
// See https://github.com/axios/axios/issues/69
|
||||
@@ -2225,7 +2265,7 @@ function httpAdapter(config) {
|
||||
data = stream__default["default"].Readable.from(data, {objectMode: false});
|
||||
}
|
||||
|
||||
data = stream__default["default"].pipeline([data, new AxiosTransformStream({
|
||||
data = stream__default["default"].pipeline([data, new AxiosTransformStream$1({
|
||||
length: utils.toFiniteNumber(contentLength),
|
||||
maxRate: utils.toFiniteNumber(maxUploadRate)
|
||||
})], utils.noop);
|
||||
@@ -2360,7 +2400,7 @@ function httpAdapter(config) {
|
||||
if (onDownloadProgress) {
|
||||
const responseLength = +res.headers['content-length'];
|
||||
|
||||
const transformStream = new AxiosTransformStream({
|
||||
const transformStream = new AxiosTransformStream$1({
|
||||
length: utils.toFiniteNumber(responseLength),
|
||||
maxRate: utils.toFiniteNumber(maxDownloadRate)
|
||||
});
|
||||
@@ -2384,7 +2424,7 @@ function httpAdapter(config) {
|
||||
const response = {
|
||||
status: res.statusCode,
|
||||
statusText: res.statusMessage,
|
||||
headers: new AxiosHeaders(res.headers),
|
||||
headers: new AxiosHeaders$1(res.headers),
|
||||
config,
|
||||
request: lastRequest
|
||||
};
|
||||
@@ -2669,7 +2709,8 @@ function progressEventReducer(listener, isDownloadStream) {
|
||||
progress: total ? (loaded / total) : undefined,
|
||||
bytes: progressBytes,
|
||||
rate: rate ? rate : undefined,
|
||||
estimated: rate && total && inRange ? (total - loaded) / rate : undefined
|
||||
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
||||
event: e
|
||||
};
|
||||
|
||||
data[isDownloadStream ? 'download' : 'upload'] = true;
|
||||
@@ -2681,7 +2722,7 @@ function progressEventReducer(listener, isDownloadStream) {
|
||||
function xhrAdapter(config) {
|
||||
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
||||
let requestData = config.data;
|
||||
const requestHeaders = AxiosHeaders.from(config.headers).normalize();
|
||||
const requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
|
||||
const responseType = config.responseType;
|
||||
let onCanceled;
|
||||
function done() {
|
||||
@@ -2719,7 +2760,7 @@ function xhrAdapter(config) {
|
||||
return;
|
||||
}
|
||||
// Prepare the response
|
||||
const responseHeaders = AxiosHeaders.from(
|
||||
const responseHeaders = AxiosHeaders$1.from(
|
||||
'getAllResponseHeaders' in request && request.getAllResponseHeaders()
|
||||
);
|
||||
const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
|
||||
@@ -2912,7 +2953,7 @@ const adapters$1 = {
|
||||
};
|
||||
|
||||
const DEFAULT_CONTENT_TYPE = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
'Content-Type': undefined
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -3084,6 +3125,8 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
||||
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
||||
});
|
||||
|
||||
const defaults$1 = defaults;
|
||||
|
||||
/**
|
||||
* Transform the data for a request or a response
|
||||
*
|
||||
@@ -3093,9 +3136,9 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
||||
* @returns {*} The resulting transformed data
|
||||
*/
|
||||
function transformData(fns, response) {
|
||||
const config = this || defaults;
|
||||
const config = this || defaults$1;
|
||||
const context = response || config;
|
||||
const headers = AxiosHeaders.from(context.headers);
|
||||
const headers = AxiosHeaders$1.from(context.headers);
|
||||
let data = context.data;
|
||||
|
||||
utils.forEach(fns, function transform(fn) {
|
||||
@@ -3138,7 +3181,7 @@ function throwIfCancellationRequested(config) {
|
||||
function dispatchRequest(config) {
|
||||
throwIfCancellationRequested(config);
|
||||
|
||||
config.headers = AxiosHeaders.from(config.headers);
|
||||
config.headers = AxiosHeaders$1.from(config.headers);
|
||||
|
||||
// Transform request data
|
||||
config.data = transformData.call(
|
||||
@@ -3146,7 +3189,11 @@ function dispatchRequest(config) {
|
||||
config.transformRequest
|
||||
);
|
||||
|
||||
const adapter = config.adapter || defaults.adapter;
|
||||
if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
|
||||
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
||||
}
|
||||
|
||||
const adapter = config.adapter || defaults$1.adapter;
|
||||
|
||||
return adapter(config).then(function onAdapterResolution(response) {
|
||||
throwIfCancellationRequested(config);
|
||||
@@ -3158,7 +3205,7 @@ function dispatchRequest(config) {
|
||||
response
|
||||
);
|
||||
|
||||
response.headers = AxiosHeaders.from(response.headers);
|
||||
response.headers = AxiosHeaders$1.from(response.headers);
|
||||
|
||||
return response;
|
||||
}, function onAdapterRejection(reason) {
|
||||
@@ -3172,7 +3219,7 @@ function dispatchRequest(config) {
|
||||
config.transformResponse,
|
||||
reason.response
|
||||
);
|
||||
reason.response.headers = AxiosHeaders.from(reason.response.headers);
|
||||
reason.response.headers = AxiosHeaders$1.from(reason.response.headers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3180,6 +3227,8 @@ function dispatchRequest(config) {
|
||||
});
|
||||
}
|
||||
|
||||
const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? thing.toJSON() : thing;
|
||||
|
||||
/**
|
||||
* Config-specific merge-function which creates a new config-object
|
||||
* by merging two configuration objects together.
|
||||
@@ -3194,9 +3243,9 @@ function mergeConfig(config1, config2) {
|
||||
config2 = config2 || {};
|
||||
const config = {};
|
||||
|
||||
function getMergedValue(target, source) {
|
||||
function getMergedValue(target, source, caseless) {
|
||||
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
||||
return utils.merge(target, source);
|
||||
return utils.merge.call({caseless}, target, source);
|
||||
} else if (utils.isPlainObject(source)) {
|
||||
return utils.merge({}, source);
|
||||
} else if (utils.isArray(source)) {
|
||||
@@ -3206,72 +3255,73 @@ function mergeConfig(config1, config2) {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
function mergeDeepProperties(prop) {
|
||||
if (!utils.isUndefined(config2[prop])) {
|
||||
return getMergedValue(config1[prop], config2[prop]);
|
||||
} else if (!utils.isUndefined(config1[prop])) {
|
||||
return getMergedValue(undefined, config1[prop]);
|
||||
function mergeDeepProperties(a, b, caseless) {
|
||||
if (!utils.isUndefined(b)) {
|
||||
return getMergedValue(a, b, caseless);
|
||||
} else if (!utils.isUndefined(a)) {
|
||||
return getMergedValue(undefined, a, caseless);
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
function valueFromConfig2(prop) {
|
||||
if (!utils.isUndefined(config2[prop])) {
|
||||
return getMergedValue(undefined, config2[prop]);
|
||||
function valueFromConfig2(a, b) {
|
||||
if (!utils.isUndefined(b)) {
|
||||
return getMergedValue(undefined, b);
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
function defaultToConfig2(prop) {
|
||||
if (!utils.isUndefined(config2[prop])) {
|
||||
return getMergedValue(undefined, config2[prop]);
|
||||
} else if (!utils.isUndefined(config1[prop])) {
|
||||
return getMergedValue(undefined, config1[prop]);
|
||||
function defaultToConfig2(a, b) {
|
||||
if (!utils.isUndefined(b)) {
|
||||
return getMergedValue(undefined, b);
|
||||
} else if (!utils.isUndefined(a)) {
|
||||
return getMergedValue(undefined, a);
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
function mergeDirectKeys(prop) {
|
||||
function mergeDirectKeys(a, b, prop) {
|
||||
if (prop in config2) {
|
||||
return getMergedValue(config1[prop], config2[prop]);
|
||||
return getMergedValue(a, b);
|
||||
} else if (prop in config1) {
|
||||
return getMergedValue(undefined, config1[prop]);
|
||||
return getMergedValue(undefined, a);
|
||||
}
|
||||
}
|
||||
|
||||
const mergeMap = {
|
||||
'url': valueFromConfig2,
|
||||
'method': valueFromConfig2,
|
||||
'data': valueFromConfig2,
|
||||
'baseURL': defaultToConfig2,
|
||||
'transformRequest': defaultToConfig2,
|
||||
'transformResponse': defaultToConfig2,
|
||||
'paramsSerializer': defaultToConfig2,
|
||||
'timeout': defaultToConfig2,
|
||||
'timeoutMessage': defaultToConfig2,
|
||||
'withCredentials': defaultToConfig2,
|
||||
'adapter': defaultToConfig2,
|
||||
'responseType': defaultToConfig2,
|
||||
'xsrfCookieName': defaultToConfig2,
|
||||
'xsrfHeaderName': defaultToConfig2,
|
||||
'onUploadProgress': defaultToConfig2,
|
||||
'onDownloadProgress': defaultToConfig2,
|
||||
'decompress': defaultToConfig2,
|
||||
'maxContentLength': defaultToConfig2,
|
||||
'maxBodyLength': defaultToConfig2,
|
||||
'beforeRedirect': defaultToConfig2,
|
||||
'transport': defaultToConfig2,
|
||||
'httpAgent': defaultToConfig2,
|
||||
'httpsAgent': defaultToConfig2,
|
||||
'cancelToken': defaultToConfig2,
|
||||
'socketPath': defaultToConfig2,
|
||||
'responseEncoding': defaultToConfig2,
|
||||
'validateStatus': mergeDirectKeys
|
||||
url: valueFromConfig2,
|
||||
method: valueFromConfig2,
|
||||
data: valueFromConfig2,
|
||||
baseURL: defaultToConfig2,
|
||||
transformRequest: defaultToConfig2,
|
||||
transformResponse: defaultToConfig2,
|
||||
paramsSerializer: defaultToConfig2,
|
||||
timeout: defaultToConfig2,
|
||||
timeoutMessage: defaultToConfig2,
|
||||
withCredentials: defaultToConfig2,
|
||||
adapter: defaultToConfig2,
|
||||
responseType: defaultToConfig2,
|
||||
xsrfCookieName: defaultToConfig2,
|
||||
xsrfHeaderName: defaultToConfig2,
|
||||
onUploadProgress: defaultToConfig2,
|
||||
onDownloadProgress: defaultToConfig2,
|
||||
decompress: defaultToConfig2,
|
||||
maxContentLength: defaultToConfig2,
|
||||
maxBodyLength: defaultToConfig2,
|
||||
beforeRedirect: defaultToConfig2,
|
||||
transport: defaultToConfig2,
|
||||
httpAgent: defaultToConfig2,
|
||||
httpsAgent: defaultToConfig2,
|
||||
cancelToken: defaultToConfig2,
|
||||
socketPath: defaultToConfig2,
|
||||
responseEncoding: defaultToConfig2,
|
||||
validateStatus: mergeDirectKeys,
|
||||
headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
|
||||
};
|
||||
|
||||
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
|
||||
const merge = mergeMap[prop] || mergeDeepProperties;
|
||||
const configValue = merge(prop);
|
||||
const configValue = merge(config1[prop], config2[prop], prop);
|
||||
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
||||
});
|
||||
|
||||
@@ -3378,8 +3428,8 @@ class Axios {
|
||||
constructor(instanceConfig) {
|
||||
this.defaults = instanceConfig;
|
||||
this.interceptors = {
|
||||
request: new InterceptorManager(),
|
||||
response: new InterceptorManager()
|
||||
request: new InterceptorManager$1(),
|
||||
response: new InterceptorManager$1()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3403,7 +3453,7 @@ class Axios {
|
||||
|
||||
config = mergeConfig(this.defaults, config);
|
||||
|
||||
const {transitional, paramsSerializer} = config;
|
||||
const {transitional, paramsSerializer, headers} = config;
|
||||
|
||||
if (transitional !== undefined) {
|
||||
validator.assertOptions(transitional, {
|
||||
@@ -3423,20 +3473,22 @@ class Axios {
|
||||
// Set config.method
|
||||
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
||||
|
||||
let contextHeaders;
|
||||
|
||||
// Flatten headers
|
||||
const defaultHeaders = config.headers && utils.merge(
|
||||
config.headers.common,
|
||||
config.headers[config.method]
|
||||
contextHeaders = headers && utils.merge(
|
||||
headers.common,
|
||||
headers[config.method]
|
||||
);
|
||||
|
||||
defaultHeaders && utils.forEach(
|
||||
contextHeaders && utils.forEach(
|
||||
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
||||
function cleanHeaderConfig(method) {
|
||||
delete config.headers[method];
|
||||
(method) => {
|
||||
delete headers[method];
|
||||
}
|
||||
);
|
||||
|
||||
config.headers = new AxiosHeaders(config.headers, defaultHeaders);
|
||||
config.headers = AxiosHeaders$1.concat(contextHeaders, headers);
|
||||
|
||||
// filter out skipped interceptors
|
||||
const requestInterceptorChain = [];
|
||||
@@ -3548,6 +3600,8 @@ utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
||||
Axios.prototype[method + 'Form'] = generateHTTPMethod(true);
|
||||
});
|
||||
|
||||
const Axios$1 = Axios;
|
||||
|
||||
/**
|
||||
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
||||
*
|
||||
@@ -3664,6 +3718,8 @@ class CancelToken {
|
||||
}
|
||||
}
|
||||
|
||||
const CancelToken$1 = CancelToken;
|
||||
|
||||
/**
|
||||
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
||||
*
|
||||
@@ -3710,11 +3766,11 @@ function isAxiosError(payload) {
|
||||
* @returns {Axios} A new instance of Axios
|
||||
*/
|
||||
function createInstance(defaultConfig) {
|
||||
const context = new Axios(defaultConfig);
|
||||
const instance = bind(Axios.prototype.request, context);
|
||||
const context = new Axios$1(defaultConfig);
|
||||
const instance = bind(Axios$1.prototype.request, context);
|
||||
|
||||
// Copy axios.prototype to instance
|
||||
utils.extend(instance, Axios.prototype, context, {allOwnKeys: true});
|
||||
utils.extend(instance, Axios$1.prototype, context, {allOwnKeys: true});
|
||||
|
||||
// Copy context to instance
|
||||
utils.extend(instance, context, null, {allOwnKeys: true});
|
||||
@@ -3728,14 +3784,14 @@ function createInstance(defaultConfig) {
|
||||
}
|
||||
|
||||
// Create the default instance to be exported
|
||||
const axios = createInstance(defaults);
|
||||
const axios = createInstance(defaults$1);
|
||||
|
||||
// Expose Axios class to allow class inheritance
|
||||
axios.Axios = Axios;
|
||||
axios.Axios = Axios$1;
|
||||
|
||||
// Expose Cancel & CancelToken
|
||||
axios.CanceledError = CanceledError;
|
||||
axios.CancelToken = CancelToken;
|
||||
axios.CancelToken = CancelToken$1;
|
||||
axios.isCancel = isCancel;
|
||||
axios.VERSION = VERSION;
|
||||
axios.toFormData = toFormData;
|
||||
@@ -3756,9 +3812,11 @@ axios.spread = spread;
|
||||
// Expose isAxiosError
|
||||
axios.isAxiosError = isAxiosError;
|
||||
|
||||
axios.formToJSON = thing => {
|
||||
return formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
||||
};
|
||||
axios.AxiosHeaders = AxiosHeaders$1;
|
||||
|
||||
axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
||||
|
||||
axios.default = axios;
|
||||
|
||||
module.exports = axios;
|
||||
//# sourceMappingURL=axios.cjs.map
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user