axios 1.6.7 → 1.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of axios might be problematic. Click here for more details.
- package/CHANGELOG.md +875 -763
- package/README.md +65 -17
- package/dist/axios.js +1413 -573
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +764 -308
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +764 -308
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +778 -390
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +5 -2
- package/index.d.ts +5 -2
- package/lib/adapters/adapters.js +3 -1
- package/lib/adapters/fetch.js +229 -0
- package/lib/adapters/http.js +26 -16
- package/lib/adapters/xhr.js +36 -99
- package/lib/core/Axios.js +9 -6
- package/lib/core/AxiosHeaders.js +4 -0
- package/lib/core/mergeConfig.js +1 -1
- package/lib/defaults/index.js +7 -2
- package/lib/env/data.js +1 -1
- package/lib/helpers/AxiosTransformStream.js +3 -51
- package/lib/helpers/composeSignals.js +46 -0
- package/lib/helpers/progressEventReducer.js +44 -0
- package/lib/helpers/resolveConfig.js +57 -0
- package/lib/helpers/throttle.js +30 -19
- package/lib/helpers/trackStream.js +67 -0
- package/lib/platform/common/utils.js +4 -1
- package/lib/utils.js +40 -3
- package/package.json +27 -26
package/dist/browser/axios.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
// Axios v1.
|
1
|
+
// Axios v1.7.3 Copyright (c) 2024 Matt Zabriskie and contributors
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
function bind(fn, thisArg) {
|
@@ -214,6 +214,8 @@ const isFormData = (thing) => {
|
|
214
214
|
*/
|
215
215
|
const isURLSearchParams = kindOfTest('URLSearchParams');
|
216
216
|
|
217
|
+
const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
|
218
|
+
|
217
219
|
/**
|
218
220
|
* Trim excess whitespace off the beginning and end of a string
|
219
221
|
*
|
@@ -602,8 +604,7 @@ const toObjectSet = (arrayOrString, delimiter) => {
|
|
602
604
|
const noop = () => {};
|
603
605
|
|
604
606
|
const toFiniteNumber = (value, defaultValue) => {
|
605
|
-
value = +value;
|
606
|
-
return Number.isFinite(value) ? value : defaultValue;
|
607
|
+
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
607
608
|
};
|
608
609
|
|
609
610
|
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
@@ -673,6 +674,36 @@ const isAsyncFn = kindOfTest('AsyncFunction');
|
|
673
674
|
const isThenable = (thing) =>
|
674
675
|
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
675
676
|
|
677
|
+
// original code
|
678
|
+
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
679
|
+
|
680
|
+
const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
681
|
+
if (setImmediateSupported) {
|
682
|
+
return setImmediate;
|
683
|
+
}
|
684
|
+
|
685
|
+
return postMessageSupported ? ((token, callbacks) => {
|
686
|
+
_global.addEventListener("message", ({source, data}) => {
|
687
|
+
if (source === _global && data === token) {
|
688
|
+
callbacks.length && callbacks.shift()();
|
689
|
+
}
|
690
|
+
}, false);
|
691
|
+
|
692
|
+
return (cb) => {
|
693
|
+
callbacks.push(cb);
|
694
|
+
_global.postMessage(token, "*");
|
695
|
+
}
|
696
|
+
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
697
|
+
})(
|
698
|
+
typeof setImmediate === 'function',
|
699
|
+
isFunction(_global.postMessage)
|
700
|
+
);
|
701
|
+
|
702
|
+
const asap = typeof queueMicrotask !== 'undefined' ?
|
703
|
+
queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
|
704
|
+
|
705
|
+
// *********************
|
706
|
+
|
676
707
|
var utils$1 = {
|
677
708
|
isArray,
|
678
709
|
isArrayBuffer,
|
@@ -684,6 +715,10 @@ var utils$1 = {
|
|
684
715
|
isBoolean,
|
685
716
|
isObject,
|
686
717
|
isPlainObject,
|
718
|
+
isReadableStream,
|
719
|
+
isRequest,
|
720
|
+
isResponse,
|
721
|
+
isHeaders,
|
687
722
|
isUndefined,
|
688
723
|
isDate,
|
689
724
|
isFile,
|
@@ -724,7 +759,9 @@ var utils$1 = {
|
|
724
759
|
isSpecCompliantForm,
|
725
760
|
toJSONObject,
|
726
761
|
isAsyncFn,
|
727
|
-
isThenable
|
762
|
+
isThenable,
|
763
|
+
setImmediate: _setImmediate,
|
764
|
+
asap
|
728
765
|
};
|
729
766
|
|
730
767
|
/**
|
@@ -1280,11 +1317,14 @@ const hasStandardBrowserWebWorkerEnv = (() => {
|
|
1280
1317
|
);
|
1281
1318
|
})();
|
1282
1319
|
|
1320
|
+
const origin = hasBrowserEnv && window.location.href || 'http://localhost';
|
1321
|
+
|
1283
1322
|
var utils = /*#__PURE__*/Object.freeze({
|
1284
1323
|
__proto__: null,
|
1285
1324
|
hasBrowserEnv: hasBrowserEnv,
|
1286
1325
|
hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
|
1287
|
-
hasStandardBrowserEnv: hasStandardBrowserEnv
|
1326
|
+
hasStandardBrowserEnv: hasStandardBrowserEnv,
|
1327
|
+
origin: origin
|
1288
1328
|
});
|
1289
1329
|
|
1290
1330
|
var platform = {
|
@@ -1424,7 +1464,7 @@ const defaults = {
|
|
1424
1464
|
|
1425
1465
|
transitional: transitionalDefaults,
|
1426
1466
|
|
1427
|
-
adapter: ['xhr', 'http'],
|
1467
|
+
adapter: ['xhr', 'http', 'fetch'],
|
1428
1468
|
|
1429
1469
|
transformRequest: [function transformRequest(data, headers) {
|
1430
1470
|
const contentType = headers.getContentType() || '';
|
@@ -1445,7 +1485,8 @@ const defaults = {
|
|
1445
1485
|
utils$1.isBuffer(data) ||
|
1446
1486
|
utils$1.isStream(data) ||
|
1447
1487
|
utils$1.isFile(data) ||
|
1448
|
-
utils$1.isBlob(data)
|
1488
|
+
utils$1.isBlob(data) ||
|
1489
|
+
utils$1.isReadableStream(data)
|
1449
1490
|
) {
|
1450
1491
|
return data;
|
1451
1492
|
}
|
@@ -1488,6 +1529,10 @@ const defaults = {
|
|
1488
1529
|
const forcedJSONParsing = transitional && transitional.forcedJSONParsing;
|
1489
1530
|
const JSONRequested = this.responseType === 'json';
|
1490
1531
|
|
1532
|
+
if (utils$1.isResponse(data) || utils$1.isReadableStream(data)) {
|
1533
|
+
return data;
|
1534
|
+
}
|
1535
|
+
|
1491
1536
|
if (data && utils$1.isString(data) && ((forcedJSONParsing && !this.responseType) || JSONRequested)) {
|
1492
1537
|
const silentJSONParsing = transitional && transitional.silentJSONParsing;
|
1493
1538
|
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
@@ -1691,6 +1736,10 @@ class AxiosHeaders {
|
|
1691
1736
|
setHeaders(header, valueOrRewrite);
|
1692
1737
|
} else if(utils$1.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
1693
1738
|
setHeaders(parseHeaders(header), valueOrRewrite);
|
1739
|
+
} else if (utils$1.isHeaders(header)) {
|
1740
|
+
for (const [key, value] of header.entries()) {
|
1741
|
+
setHeader(value, key, rewrite);
|
1742
|
+
}
|
1694
1743
|
} else {
|
1695
1744
|
header != null && setHeader(valueOrRewrite, header, rewrite);
|
1696
1745
|
}
|
@@ -1958,90 +2007,147 @@ function settle(resolve, reject, response) {
|
|
1958
2007
|
}
|
1959
2008
|
}
|
1960
2009
|
|
1961
|
-
|
2010
|
+
function parseProtocol(url) {
|
2011
|
+
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
2012
|
+
return match && match[1] || '';
|
2013
|
+
}
|
1962
2014
|
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
2015
|
+
/**
|
2016
|
+
* Calculate data maxRate
|
2017
|
+
* @param {Number} [samplesCount= 10]
|
2018
|
+
* @param {Number} [min= 1000]
|
2019
|
+
* @returns {Function}
|
2020
|
+
*/
|
2021
|
+
function speedometer(samplesCount, min) {
|
2022
|
+
samplesCount = samplesCount || 10;
|
2023
|
+
const bytes = new Array(samplesCount);
|
2024
|
+
const timestamps = new Array(samplesCount);
|
2025
|
+
let head = 0;
|
2026
|
+
let tail = 0;
|
2027
|
+
let firstSampleTS;
|
1967
2028
|
|
1968
|
-
|
2029
|
+
min = min !== undefined ? min : 1000;
|
1969
2030
|
|
1970
|
-
|
2031
|
+
return function push(chunkLength) {
|
2032
|
+
const now = Date.now();
|
1971
2033
|
|
1972
|
-
|
2034
|
+
const startedAt = timestamps[tail];
|
1973
2035
|
|
1974
|
-
|
2036
|
+
if (!firstSampleTS) {
|
2037
|
+
firstSampleTS = now;
|
2038
|
+
}
|
1975
2039
|
|
1976
|
-
|
1977
|
-
|
2040
|
+
bytes[head] = chunkLength;
|
2041
|
+
timestamps[head] = now;
|
1978
2042
|
|
1979
|
-
|
1980
|
-
|
1981
|
-
return (match ? decodeURIComponent(match[3]) : null);
|
1982
|
-
},
|
2043
|
+
let i = tail;
|
2044
|
+
let bytesCount = 0;
|
1983
2045
|
|
1984
|
-
|
1985
|
-
|
2046
|
+
while (i !== head) {
|
2047
|
+
bytesCount += bytes[i++];
|
2048
|
+
i = i % samplesCount;
|
1986
2049
|
}
|
1987
|
-
}
|
1988
2050
|
|
1989
|
-
|
2051
|
+
head = (head + 1) % samplesCount;
|
1990
2052
|
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
read() {
|
1995
|
-
return null;
|
1996
|
-
},
|
1997
|
-
remove() {}
|
1998
|
-
};
|
2053
|
+
if (head === tail) {
|
2054
|
+
tail = (tail + 1) % samplesCount;
|
2055
|
+
}
|
1999
2056
|
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
* @param {string} url The URL to test
|
2004
|
-
*
|
2005
|
-
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
2006
|
-
*/
|
2007
|
-
function isAbsoluteURL(url) {
|
2008
|
-
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
2009
|
-
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
2010
|
-
// by any combination of letters, digits, plus, period, or hyphen.
|
2011
|
-
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
2012
|
-
}
|
2057
|
+
if (now - firstSampleTS < min) {
|
2058
|
+
return;
|
2059
|
+
}
|
2013
2060
|
|
2014
|
-
|
2015
|
-
|
2016
|
-
*
|
2017
|
-
|
2018
|
-
* @param {string} relativeURL The relative URL
|
2019
|
-
*
|
2020
|
-
* @returns {string} The combined URL
|
2021
|
-
*/
|
2022
|
-
function combineURLs(baseURL, relativeURL) {
|
2023
|
-
return relativeURL
|
2024
|
-
? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
2025
|
-
: baseURL;
|
2061
|
+
const passed = startedAt && now - startedAt;
|
2062
|
+
|
2063
|
+
return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
|
2064
|
+
};
|
2026
2065
|
}
|
2027
2066
|
|
2028
2067
|
/**
|
2029
|
-
*
|
2030
|
-
*
|
2031
|
-
*
|
2032
|
-
*
|
2033
|
-
* @param {string} baseURL The base URL
|
2034
|
-
* @param {string} requestedURL Absolute or relative URL to combine
|
2035
|
-
*
|
2036
|
-
* @returns {string} The combined full path
|
2068
|
+
* Throttle decorator
|
2069
|
+
* @param {Function} fn
|
2070
|
+
* @param {Number} freq
|
2071
|
+
* @return {Function}
|
2037
2072
|
*/
|
2038
|
-
function
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2073
|
+
function throttle(fn, freq) {
|
2074
|
+
let timestamp = 0;
|
2075
|
+
let threshold = 1000 / freq;
|
2076
|
+
let lastArgs;
|
2077
|
+
let timer;
|
2078
|
+
|
2079
|
+
const invoke = (args, now = Date.now()) => {
|
2080
|
+
timestamp = now;
|
2081
|
+
lastArgs = null;
|
2082
|
+
if (timer) {
|
2083
|
+
clearTimeout(timer);
|
2084
|
+
timer = null;
|
2085
|
+
}
|
2086
|
+
fn.apply(null, args);
|
2087
|
+
};
|
2088
|
+
|
2089
|
+
const throttled = (...args) => {
|
2090
|
+
const now = Date.now();
|
2091
|
+
const passed = now - timestamp;
|
2092
|
+
if ( passed >= threshold) {
|
2093
|
+
invoke(args, now);
|
2094
|
+
} else {
|
2095
|
+
lastArgs = args;
|
2096
|
+
if (!timer) {
|
2097
|
+
timer = setTimeout(() => {
|
2098
|
+
timer = null;
|
2099
|
+
invoke(lastArgs);
|
2100
|
+
}, threshold - passed);
|
2101
|
+
}
|
2102
|
+
}
|
2103
|
+
};
|
2104
|
+
|
2105
|
+
const flush = () => lastArgs && invoke(lastArgs);
|
2106
|
+
|
2107
|
+
return [throttled, flush];
|
2043
2108
|
}
|
2044
2109
|
|
2110
|
+
const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
2111
|
+
let bytesNotified = 0;
|
2112
|
+
const _speedometer = speedometer(50, 250);
|
2113
|
+
|
2114
|
+
return throttle(e => {
|
2115
|
+
const loaded = e.loaded;
|
2116
|
+
const total = e.lengthComputable ? e.total : undefined;
|
2117
|
+
const progressBytes = loaded - bytesNotified;
|
2118
|
+
const rate = _speedometer(progressBytes);
|
2119
|
+
const inRange = loaded <= total;
|
2120
|
+
|
2121
|
+
bytesNotified = loaded;
|
2122
|
+
|
2123
|
+
const data = {
|
2124
|
+
loaded,
|
2125
|
+
total,
|
2126
|
+
progress: total ? (loaded / total) : undefined,
|
2127
|
+
bytes: progressBytes,
|
2128
|
+
rate: rate ? rate : undefined,
|
2129
|
+
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
2130
|
+
event: e,
|
2131
|
+
lengthComputable: total != null,
|
2132
|
+
[isDownloadStream ? 'download' : 'upload']: true
|
2133
|
+
};
|
2134
|
+
|
2135
|
+
listener(data);
|
2136
|
+
}, freq);
|
2137
|
+
};
|
2138
|
+
|
2139
|
+
const progressEventDecorator = (total, throttled) => {
|
2140
|
+
const lengthComputable = total != null;
|
2141
|
+
|
2142
|
+
return [(loaded) => throttled[0]({
|
2143
|
+
lengthComputable,
|
2144
|
+
total,
|
2145
|
+
loaded
|
2146
|
+
}), throttled[1]];
|
2147
|
+
};
|
2148
|
+
|
2149
|
+
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
2150
|
+
|
2045
2151
|
var isURLSameOrigin = platform.hasStandardBrowserEnv ?
|
2046
2152
|
|
2047
2153
|
// Standard browser envs have full support of the APIs needed to test
|
@@ -2105,137 +2211,267 @@ var isURLSameOrigin = platform.hasStandardBrowserEnv ?
|
|
2105
2211
|
};
|
2106
2212
|
})();
|
2107
2213
|
|
2108
|
-
|
2109
|
-
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
2110
|
-
return match && match[1] || '';
|
2111
|
-
}
|
2214
|
+
var cookies = platform.hasStandardBrowserEnv ?
|
2112
2215
|
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
* @returns {Function}
|
2118
|
-
*/
|
2119
|
-
function speedometer(samplesCount, min) {
|
2120
|
-
samplesCount = samplesCount || 10;
|
2121
|
-
const bytes = new Array(samplesCount);
|
2122
|
-
const timestamps = new Array(samplesCount);
|
2123
|
-
let head = 0;
|
2124
|
-
let tail = 0;
|
2125
|
-
let firstSampleTS;
|
2216
|
+
// Standard browser envs support document.cookie
|
2217
|
+
{
|
2218
|
+
write(name, value, expires, path, domain, secure) {
|
2219
|
+
const cookie = [name + '=' + encodeURIComponent(value)];
|
2126
2220
|
|
2127
|
-
|
2221
|
+
utils$1.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
|
2128
2222
|
|
2129
|
-
|
2130
|
-
const now = Date.now();
|
2223
|
+
utils$1.isString(path) && cookie.push('path=' + path);
|
2131
2224
|
|
2132
|
-
|
2225
|
+
utils$1.isString(domain) && cookie.push('domain=' + domain);
|
2133
2226
|
|
2134
|
-
|
2135
|
-
firstSampleTS = now;
|
2136
|
-
}
|
2227
|
+
secure === true && cookie.push('secure');
|
2137
2228
|
|
2138
|
-
|
2139
|
-
|
2229
|
+
document.cookie = cookie.join('; ');
|
2230
|
+
},
|
2140
2231
|
|
2141
|
-
|
2142
|
-
|
2232
|
+
read(name) {
|
2233
|
+
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
2234
|
+
return (match ? decodeURIComponent(match[3]) : null);
|
2235
|
+
},
|
2143
2236
|
|
2144
|
-
|
2145
|
-
|
2146
|
-
i = i % samplesCount;
|
2237
|
+
remove(name) {
|
2238
|
+
this.write(name, '', Date.now() - 86400000);
|
2147
2239
|
}
|
2240
|
+
}
|
2148
2241
|
|
2149
|
-
|
2150
|
-
|
2151
|
-
if (head === tail) {
|
2152
|
-
tail = (tail + 1) % samplesCount;
|
2153
|
-
}
|
2242
|
+
:
|
2154
2243
|
|
2155
|
-
|
2156
|
-
|
2157
|
-
}
|
2244
|
+
// Non-standard browser env (web workers, react-native) lack needed support.
|
2245
|
+
{
|
2246
|
+
write() {},
|
2247
|
+
read() {
|
2248
|
+
return null;
|
2249
|
+
},
|
2250
|
+
remove() {}
|
2251
|
+
};
|
2158
2252
|
|
2159
|
-
|
2253
|
+
/**
|
2254
|
+
* Determines whether the specified URL is absolute
|
2255
|
+
*
|
2256
|
+
* @param {string} url The URL to test
|
2257
|
+
*
|
2258
|
+
* @returns {boolean} True if the specified URL is absolute, otherwise false
|
2259
|
+
*/
|
2260
|
+
function isAbsoluteURL(url) {
|
2261
|
+
// A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
|
2262
|
+
// RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
|
2263
|
+
// by any combination of letters, digits, plus, period, or hyphen.
|
2264
|
+
return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
|
2265
|
+
}
|
2160
2266
|
|
2161
|
-
|
2162
|
-
|
2267
|
+
/**
|
2268
|
+
* Creates a new URL by combining the specified URLs
|
2269
|
+
*
|
2270
|
+
* @param {string} baseURL The base URL
|
2271
|
+
* @param {string} relativeURL The relative URL
|
2272
|
+
*
|
2273
|
+
* @returns {string} The combined URL
|
2274
|
+
*/
|
2275
|
+
function combineURLs(baseURL, relativeURL) {
|
2276
|
+
return relativeURL
|
2277
|
+
? baseURL.replace(/\/?\/$/, '') + '/' + relativeURL.replace(/^\/+/, '')
|
2278
|
+
: baseURL;
|
2163
2279
|
}
|
2164
2280
|
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2281
|
+
/**
|
2282
|
+
* Creates a new URL by combining the baseURL with the requestedURL,
|
2283
|
+
* only when the requestedURL is not already an absolute URL.
|
2284
|
+
* If the requestURL is absolute, this function returns the requestedURL untouched.
|
2285
|
+
*
|
2286
|
+
* @param {string} baseURL The base URL
|
2287
|
+
* @param {string} requestedURL Absolute or relative URL to combine
|
2288
|
+
*
|
2289
|
+
* @returns {string} The combined full path
|
2290
|
+
*/
|
2291
|
+
function buildFullPath(baseURL, requestedURL) {
|
2292
|
+
if (baseURL && !isAbsoluteURL(requestedURL)) {
|
2293
|
+
return combineURLs(baseURL, requestedURL);
|
2294
|
+
}
|
2295
|
+
return requestedURL;
|
2296
|
+
}
|
2168
2297
|
|
2169
|
-
|
2170
|
-
const loaded = e.loaded;
|
2171
|
-
const total = e.lengthComputable ? e.total : undefined;
|
2172
|
-
const progressBytes = loaded - bytesNotified;
|
2173
|
-
const rate = _speedometer(progressBytes);
|
2174
|
-
const inRange = loaded <= total;
|
2298
|
+
const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? { ...thing } : thing;
|
2175
2299
|
|
2176
|
-
|
2300
|
+
/**
|
2301
|
+
* Config-specific merge-function which creates a new config-object
|
2302
|
+
* by merging two configuration objects together.
|
2303
|
+
*
|
2304
|
+
* @param {Object} config1
|
2305
|
+
* @param {Object} config2
|
2306
|
+
*
|
2307
|
+
* @returns {Object} New object resulting from merging config2 to config1
|
2308
|
+
*/
|
2309
|
+
function mergeConfig(config1, config2) {
|
2310
|
+
// eslint-disable-next-line no-param-reassign
|
2311
|
+
config2 = config2 || {};
|
2312
|
+
const config = {};
|
2177
2313
|
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2314
|
+
function getMergedValue(target, source, caseless) {
|
2315
|
+
if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
|
2316
|
+
return utils$1.merge.call({caseless}, target, source);
|
2317
|
+
} else if (utils$1.isPlainObject(source)) {
|
2318
|
+
return utils$1.merge({}, source);
|
2319
|
+
} else if (utils$1.isArray(source)) {
|
2320
|
+
return source.slice();
|
2321
|
+
}
|
2322
|
+
return source;
|
2323
|
+
}
|
2324
|
+
|
2325
|
+
// eslint-disable-next-line consistent-return
|
2326
|
+
function mergeDeepProperties(a, b, caseless) {
|
2327
|
+
if (!utils$1.isUndefined(b)) {
|
2328
|
+
return getMergedValue(a, b, caseless);
|
2329
|
+
} else if (!utils$1.isUndefined(a)) {
|
2330
|
+
return getMergedValue(undefined, a, caseless);
|
2331
|
+
}
|
2332
|
+
}
|
2187
2333
|
|
2188
|
-
|
2334
|
+
// eslint-disable-next-line consistent-return
|
2335
|
+
function valueFromConfig2(a, b) {
|
2336
|
+
if (!utils$1.isUndefined(b)) {
|
2337
|
+
return getMergedValue(undefined, b);
|
2338
|
+
}
|
2339
|
+
}
|
2189
2340
|
|
2190
|
-
|
2341
|
+
// eslint-disable-next-line consistent-return
|
2342
|
+
function defaultToConfig2(a, b) {
|
2343
|
+
if (!utils$1.isUndefined(b)) {
|
2344
|
+
return getMergedValue(undefined, b);
|
2345
|
+
} else if (!utils$1.isUndefined(a)) {
|
2346
|
+
return getMergedValue(undefined, a);
|
2347
|
+
}
|
2348
|
+
}
|
2349
|
+
|
2350
|
+
// eslint-disable-next-line consistent-return
|
2351
|
+
function mergeDirectKeys(a, b, prop) {
|
2352
|
+
if (prop in config2) {
|
2353
|
+
return getMergedValue(a, b);
|
2354
|
+
} else if (prop in config1) {
|
2355
|
+
return getMergedValue(undefined, a);
|
2356
|
+
}
|
2357
|
+
}
|
2358
|
+
|
2359
|
+
const mergeMap = {
|
2360
|
+
url: valueFromConfig2,
|
2361
|
+
method: valueFromConfig2,
|
2362
|
+
data: valueFromConfig2,
|
2363
|
+
baseURL: defaultToConfig2,
|
2364
|
+
transformRequest: defaultToConfig2,
|
2365
|
+
transformResponse: defaultToConfig2,
|
2366
|
+
paramsSerializer: defaultToConfig2,
|
2367
|
+
timeout: defaultToConfig2,
|
2368
|
+
timeoutMessage: defaultToConfig2,
|
2369
|
+
withCredentials: defaultToConfig2,
|
2370
|
+
withXSRFToken: defaultToConfig2,
|
2371
|
+
adapter: defaultToConfig2,
|
2372
|
+
responseType: defaultToConfig2,
|
2373
|
+
xsrfCookieName: defaultToConfig2,
|
2374
|
+
xsrfHeaderName: defaultToConfig2,
|
2375
|
+
onUploadProgress: defaultToConfig2,
|
2376
|
+
onDownloadProgress: defaultToConfig2,
|
2377
|
+
decompress: defaultToConfig2,
|
2378
|
+
maxContentLength: defaultToConfig2,
|
2379
|
+
maxBodyLength: defaultToConfig2,
|
2380
|
+
beforeRedirect: defaultToConfig2,
|
2381
|
+
transport: defaultToConfig2,
|
2382
|
+
httpAgent: defaultToConfig2,
|
2383
|
+
httpsAgent: defaultToConfig2,
|
2384
|
+
cancelToken: defaultToConfig2,
|
2385
|
+
socketPath: defaultToConfig2,
|
2386
|
+
responseEncoding: defaultToConfig2,
|
2387
|
+
validateStatus: mergeDirectKeys,
|
2388
|
+
headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
|
2191
2389
|
};
|
2390
|
+
|
2391
|
+
utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
|
2392
|
+
const merge = mergeMap[prop] || mergeDeepProperties;
|
2393
|
+
const configValue = merge(config1[prop], config2[prop], prop);
|
2394
|
+
(utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
2395
|
+
});
|
2396
|
+
|
2397
|
+
return config;
|
2192
2398
|
}
|
2193
2399
|
|
2194
|
-
|
2400
|
+
var resolveConfig = (config) => {
|
2401
|
+
const newConfig = mergeConfig({}, config);
|
2195
2402
|
|
2196
|
-
|
2197
|
-
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
2198
|
-
let requestData = config.data;
|
2199
|
-
const requestHeaders = AxiosHeaders$1.from(config.headers).normalize();
|
2200
|
-
let {responseType, withXSRFToken} = config;
|
2201
|
-
let onCanceled;
|
2202
|
-
function done() {
|
2203
|
-
if (config.cancelToken) {
|
2204
|
-
config.cancelToken.unsubscribe(onCanceled);
|
2205
|
-
}
|
2403
|
+
let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
|
2206
2404
|
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2405
|
+
newConfig.headers = headers = AxiosHeaders$1.from(headers);
|
2406
|
+
|
2407
|
+
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
2408
|
+
|
2409
|
+
// HTTP basic authentication
|
2410
|
+
if (auth) {
|
2411
|
+
headers.set('Authorization', 'Basic ' +
|
2412
|
+
btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
|
2413
|
+
);
|
2414
|
+
}
|
2415
|
+
|
2416
|
+
let contentType;
|
2417
|
+
|
2418
|
+
if (utils$1.isFormData(data)) {
|
2419
|
+
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
2420
|
+
headers.setContentType(undefined); // Let the browser set it
|
2421
|
+
} else if ((contentType = headers.getContentType()) !== false) {
|
2422
|
+
// fix semicolon duplication issue for ReactNative FormData implementation
|
2423
|
+
const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
|
2424
|
+
headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
|
2210
2425
|
}
|
2426
|
+
}
|
2211
2427
|
|
2212
|
-
|
2428
|
+
// Add xsrf header
|
2429
|
+
// This is only done if running in a standard browser environment.
|
2430
|
+
// Specifically not if we're in a web worker, or react-native.
|
2213
2431
|
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2432
|
+
if (platform.hasStandardBrowserEnv) {
|
2433
|
+
withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
|
2434
|
+
|
2435
|
+
if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
|
2436
|
+
// Add xsrf header
|
2437
|
+
const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
|
2438
|
+
|
2439
|
+
if (xsrfValue) {
|
2440
|
+
headers.set(xsrfHeaderName, xsrfValue);
|
2221
2441
|
}
|
2222
2442
|
}
|
2443
|
+
}
|
2223
2444
|
|
2224
|
-
|
2445
|
+
return newConfig;
|
2446
|
+
};
|
2447
|
+
|
2448
|
+
const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
|
2449
|
+
|
2450
|
+
var xhrAdapter = isXHRAdapterSupported && function (config) {
|
2451
|
+
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
2452
|
+
const _config = resolveConfig(config);
|
2453
|
+
let requestData = _config.data;
|
2454
|
+
const requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
|
2455
|
+
let {responseType, onUploadProgress, onDownloadProgress} = _config;
|
2456
|
+
let onCanceled;
|
2457
|
+
let uploadThrottled, downloadThrottled;
|
2458
|
+
let flushUpload, flushDownload;
|
2459
|
+
|
2460
|
+
function done() {
|
2461
|
+
flushUpload && flushUpload(); // flush events
|
2462
|
+
flushDownload && flushDownload(); // flush events
|
2463
|
+
|
2464
|
+
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
2225
2465
|
|
2226
|
-
|
2227
|
-
if (config.auth) {
|
2228
|
-
const username = config.auth.username || '';
|
2229
|
-
const password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
|
2230
|
-
requestHeaders.set('Authorization', 'Basic ' + btoa(username + ':' + password));
|
2466
|
+
_config.signal && _config.signal.removeEventListener('abort', onCanceled);
|
2231
2467
|
}
|
2232
2468
|
|
2233
|
-
|
2469
|
+
let request = new XMLHttpRequest();
|
2234
2470
|
|
2235
|
-
request.open(
|
2471
|
+
request.open(_config.method.toUpperCase(), _config.url, true);
|
2236
2472
|
|
2237
2473
|
// Set the request timeout in MS
|
2238
|
-
request.timeout =
|
2474
|
+
request.timeout = _config.timeout;
|
2239
2475
|
|
2240
2476
|
function onloadend() {
|
2241
2477
|
if (!request) {
|
@@ -2315,10 +2551,10 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2315
2551
|
|
2316
2552
|
// Handle timeout
|
2317
2553
|
request.ontimeout = function handleTimeout() {
|
2318
|
-
let timeoutErrorMessage =
|
2319
|
-
const transitional =
|
2320
|
-
if (
|
2321
|
-
timeoutErrorMessage =
|
2554
|
+
let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
|
2555
|
+
const transitional = _config.transitional || transitionalDefaults;
|
2556
|
+
if (_config.timeoutErrorMessage) {
|
2557
|
+
timeoutErrorMessage = _config.timeoutErrorMessage;
|
2322
2558
|
}
|
2323
2559
|
reject(new AxiosError(
|
2324
2560
|
timeoutErrorMessage,
|
@@ -2330,22 +2566,6 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2330
2566
|
request = null;
|
2331
2567
|
};
|
2332
2568
|
|
2333
|
-
// Add xsrf header
|
2334
|
-
// This is only done if running in a standard browser environment.
|
2335
|
-
// Specifically not if we're in a web worker, or react-native.
|
2336
|
-
if(platform.hasStandardBrowserEnv) {
|
2337
|
-
withXSRFToken && utils$1.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(config));
|
2338
|
-
|
2339
|
-
if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(fullPath))) {
|
2340
|
-
// Add xsrf header
|
2341
|
-
const xsrfValue = config.xsrfHeaderName && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
|
2342
|
-
|
2343
|
-
if (xsrfValue) {
|
2344
|
-
requestHeaders.set(config.xsrfHeaderName, xsrfValue);
|
2345
|
-
}
|
2346
|
-
}
|
2347
|
-
}
|
2348
|
-
|
2349
2569
|
// Remove Content-Type if data is undefined
|
2350
2570
|
requestData === undefined && requestHeaders.setContentType(null);
|
2351
2571
|
|
@@ -2357,26 +2577,31 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2357
2577
|
}
|
2358
2578
|
|
2359
2579
|
// Add withCredentials to request if needed
|
2360
|
-
if (!utils$1.isUndefined(
|
2361
|
-
request.withCredentials = !!
|
2580
|
+
if (!utils$1.isUndefined(_config.withCredentials)) {
|
2581
|
+
request.withCredentials = !!_config.withCredentials;
|
2362
2582
|
}
|
2363
2583
|
|
2364
2584
|
// Add responseType to request if needed
|
2365
2585
|
if (responseType && responseType !== 'json') {
|
2366
|
-
request.responseType =
|
2586
|
+
request.responseType = _config.responseType;
|
2367
2587
|
}
|
2368
2588
|
|
2369
2589
|
// Handle progress if needed
|
2370
|
-
if (
|
2371
|
-
|
2590
|
+
if (onDownloadProgress) {
|
2591
|
+
([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
|
2592
|
+
request.addEventListener('progress', downloadThrottled);
|
2372
2593
|
}
|
2373
2594
|
|
2374
2595
|
// Not all browsers support upload events
|
2375
|
-
if (
|
2376
|
-
|
2596
|
+
if (onUploadProgress && request.upload) {
|
2597
|
+
([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
|
2598
|
+
|
2599
|
+
request.upload.addEventListener('progress', uploadThrottled);
|
2600
|
+
|
2601
|
+
request.upload.addEventListener('loadend', flushUpload);
|
2377
2602
|
}
|
2378
2603
|
|
2379
|
-
if (
|
2604
|
+
if (_config.cancelToken || _config.signal) {
|
2380
2605
|
// Handle cancellation
|
2381
2606
|
// eslint-disable-next-line func-names
|
2382
2607
|
onCanceled = cancel => {
|
@@ -2388,13 +2613,13 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2388
2613
|
request = null;
|
2389
2614
|
};
|
2390
2615
|
|
2391
|
-
|
2392
|
-
if (
|
2393
|
-
|
2616
|
+
_config.cancelToken && _config.cancelToken.subscribe(onCanceled);
|
2617
|
+
if (_config.signal) {
|
2618
|
+
_config.signal.aborted ? onCanceled() : _config.signal.addEventListener('abort', onCanceled);
|
2394
2619
|
}
|
2395
2620
|
}
|
2396
2621
|
|
2397
|
-
const protocol = parseProtocol(
|
2622
|
+
const protocol = parseProtocol(_config.url);
|
2398
2623
|
|
2399
2624
|
if (protocol && platform.protocols.indexOf(protocol) === -1) {
|
2400
2625
|
reject(new AxiosError('Unsupported protocol ' + protocol + ':', AxiosError.ERR_BAD_REQUEST, config));
|
@@ -2407,9 +2632,339 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
|
2407
2632
|
});
|
2408
2633
|
};
|
2409
2634
|
|
2635
|
+
const composeSignals = (signals, timeout) => {
|
2636
|
+
let controller = new AbortController();
|
2637
|
+
|
2638
|
+
let aborted;
|
2639
|
+
|
2640
|
+
const onabort = function (cancel) {
|
2641
|
+
if (!aborted) {
|
2642
|
+
aborted = true;
|
2643
|
+
unsubscribe();
|
2644
|
+
const err = cancel instanceof Error ? cancel : this.reason;
|
2645
|
+
controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
|
2646
|
+
}
|
2647
|
+
};
|
2648
|
+
|
2649
|
+
let timer = timeout && setTimeout(() => {
|
2650
|
+
onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
|
2651
|
+
}, timeout);
|
2652
|
+
|
2653
|
+
const unsubscribe = () => {
|
2654
|
+
if (signals) {
|
2655
|
+
timer && clearTimeout(timer);
|
2656
|
+
timer = null;
|
2657
|
+
signals.forEach(signal => {
|
2658
|
+
signal &&
|
2659
|
+
(signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
|
2660
|
+
});
|
2661
|
+
signals = null;
|
2662
|
+
}
|
2663
|
+
};
|
2664
|
+
|
2665
|
+
signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
|
2666
|
+
|
2667
|
+
const {signal} = controller;
|
2668
|
+
|
2669
|
+
signal.unsubscribe = unsubscribe;
|
2670
|
+
|
2671
|
+
return [signal, () => {
|
2672
|
+
timer && clearTimeout(timer);
|
2673
|
+
timer = null;
|
2674
|
+
}];
|
2675
|
+
};
|
2676
|
+
|
2677
|
+
var composeSignals$1 = composeSignals;
|
2678
|
+
|
2679
|
+
const streamChunk = function* (chunk, chunkSize) {
|
2680
|
+
let len = chunk.byteLength;
|
2681
|
+
|
2682
|
+
if (!chunkSize || len < chunkSize) {
|
2683
|
+
yield chunk;
|
2684
|
+
return;
|
2685
|
+
}
|
2686
|
+
|
2687
|
+
let pos = 0;
|
2688
|
+
let end;
|
2689
|
+
|
2690
|
+
while (pos < len) {
|
2691
|
+
end = pos + chunkSize;
|
2692
|
+
yield chunk.slice(pos, end);
|
2693
|
+
pos = end;
|
2694
|
+
}
|
2695
|
+
};
|
2696
|
+
|
2697
|
+
const readBytes = async function* (iterable, chunkSize, encode) {
|
2698
|
+
for await (const chunk of iterable) {
|
2699
|
+
yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
|
2700
|
+
}
|
2701
|
+
};
|
2702
|
+
|
2703
|
+
const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
2704
|
+
const iterator = readBytes(stream, chunkSize, encode);
|
2705
|
+
|
2706
|
+
let bytes = 0;
|
2707
|
+
let done;
|
2708
|
+
let _onFinish = (e) => {
|
2709
|
+
if (!done) {
|
2710
|
+
done = true;
|
2711
|
+
onFinish && onFinish(e);
|
2712
|
+
}
|
2713
|
+
};
|
2714
|
+
|
2715
|
+
return new ReadableStream({
|
2716
|
+
async pull(controller) {
|
2717
|
+
try {
|
2718
|
+
const {done, value} = await iterator.next();
|
2719
|
+
|
2720
|
+
if (done) {
|
2721
|
+
_onFinish();
|
2722
|
+
controller.close();
|
2723
|
+
return;
|
2724
|
+
}
|
2725
|
+
|
2726
|
+
let len = value.byteLength;
|
2727
|
+
if (onProgress) {
|
2728
|
+
let loadedBytes = bytes += len;
|
2729
|
+
onProgress(loadedBytes);
|
2730
|
+
}
|
2731
|
+
controller.enqueue(new Uint8Array(value));
|
2732
|
+
} catch (err) {
|
2733
|
+
_onFinish(err);
|
2734
|
+
throw err;
|
2735
|
+
}
|
2736
|
+
},
|
2737
|
+
cancel(reason) {
|
2738
|
+
_onFinish(reason);
|
2739
|
+
return iterator.return();
|
2740
|
+
}
|
2741
|
+
}, {
|
2742
|
+
highWaterMark: 2
|
2743
|
+
})
|
2744
|
+
};
|
2745
|
+
|
2746
|
+
const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
|
2747
|
+
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
|
2748
|
+
|
2749
|
+
// used only inside the fetch adapter
|
2750
|
+
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
2751
|
+
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
2752
|
+
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
2753
|
+
);
|
2754
|
+
|
2755
|
+
const test = (fn, ...args) => {
|
2756
|
+
try {
|
2757
|
+
return !!fn(...args);
|
2758
|
+
} catch (e) {
|
2759
|
+
return false
|
2760
|
+
}
|
2761
|
+
};
|
2762
|
+
|
2763
|
+
const supportsRequestStream = isReadableStreamSupported && test(() => {
|
2764
|
+
let duplexAccessed = false;
|
2765
|
+
|
2766
|
+
const hasContentType = new Request(platform.origin, {
|
2767
|
+
body: new ReadableStream(),
|
2768
|
+
method: 'POST',
|
2769
|
+
get duplex() {
|
2770
|
+
duplexAccessed = true;
|
2771
|
+
return 'half';
|
2772
|
+
},
|
2773
|
+
}).headers.has('Content-Type');
|
2774
|
+
|
2775
|
+
return duplexAccessed && !hasContentType;
|
2776
|
+
});
|
2777
|
+
|
2778
|
+
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
2779
|
+
|
2780
|
+
const supportsResponseStream = isReadableStreamSupported &&
|
2781
|
+
test(() => utils$1.isReadableStream(new Response('').body));
|
2782
|
+
|
2783
|
+
|
2784
|
+
const resolvers = {
|
2785
|
+
stream: supportsResponseStream && ((res) => res.body)
|
2786
|
+
};
|
2787
|
+
|
2788
|
+
isFetchSupported && (((res) => {
|
2789
|
+
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
2790
|
+
!resolvers[type] && (resolvers[type] = utils$1.isFunction(res[type]) ? (res) => res[type]() :
|
2791
|
+
(_, config) => {
|
2792
|
+
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
2793
|
+
});
|
2794
|
+
});
|
2795
|
+
})(new Response));
|
2796
|
+
|
2797
|
+
const getBodyLength = async (body) => {
|
2798
|
+
if (body == null) {
|
2799
|
+
return 0;
|
2800
|
+
}
|
2801
|
+
|
2802
|
+
if(utils$1.isBlob(body)) {
|
2803
|
+
return body.size;
|
2804
|
+
}
|
2805
|
+
|
2806
|
+
if(utils$1.isSpecCompliantForm(body)) {
|
2807
|
+
return (await new Request(body).arrayBuffer()).byteLength;
|
2808
|
+
}
|
2809
|
+
|
2810
|
+
if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
2811
|
+
return body.byteLength;
|
2812
|
+
}
|
2813
|
+
|
2814
|
+
if(utils$1.isURLSearchParams(body)) {
|
2815
|
+
body = body + '';
|
2816
|
+
}
|
2817
|
+
|
2818
|
+
if(utils$1.isString(body)) {
|
2819
|
+
return (await encodeText(body)).byteLength;
|
2820
|
+
}
|
2821
|
+
};
|
2822
|
+
|
2823
|
+
const resolveBodyLength = async (headers, body) => {
|
2824
|
+
const length = utils$1.toFiniteNumber(headers.getContentLength());
|
2825
|
+
|
2826
|
+
return length == null ? getBodyLength(body) : length;
|
2827
|
+
};
|
2828
|
+
|
2829
|
+
var fetchAdapter = isFetchSupported && (async (config) => {
|
2830
|
+
let {
|
2831
|
+
url,
|
2832
|
+
method,
|
2833
|
+
data,
|
2834
|
+
signal,
|
2835
|
+
cancelToken,
|
2836
|
+
timeout,
|
2837
|
+
onDownloadProgress,
|
2838
|
+
onUploadProgress,
|
2839
|
+
responseType,
|
2840
|
+
headers,
|
2841
|
+
withCredentials = 'same-origin',
|
2842
|
+
fetchOptions
|
2843
|
+
} = resolveConfig(config);
|
2844
|
+
|
2845
|
+
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
2846
|
+
|
2847
|
+
let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
|
2848
|
+
composeSignals$1([signal, cancelToken], timeout) : [];
|
2849
|
+
|
2850
|
+
let finished, request;
|
2851
|
+
|
2852
|
+
const onFinish = () => {
|
2853
|
+
!finished && setTimeout(() => {
|
2854
|
+
composedSignal && composedSignal.unsubscribe();
|
2855
|
+
});
|
2856
|
+
|
2857
|
+
finished = true;
|
2858
|
+
};
|
2859
|
+
|
2860
|
+
let requestContentLength;
|
2861
|
+
|
2862
|
+
try {
|
2863
|
+
if (
|
2864
|
+
onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
|
2865
|
+
(requestContentLength = await resolveBodyLength(headers, data)) !== 0
|
2866
|
+
) {
|
2867
|
+
let _request = new Request(url, {
|
2868
|
+
method: 'POST',
|
2869
|
+
body: data,
|
2870
|
+
duplex: "half"
|
2871
|
+
});
|
2872
|
+
|
2873
|
+
let contentTypeHeader;
|
2874
|
+
|
2875
|
+
if (utils$1.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
|
2876
|
+
headers.setContentType(contentTypeHeader);
|
2877
|
+
}
|
2878
|
+
|
2879
|
+
if (_request.body) {
|
2880
|
+
const [onProgress, flush] = progressEventDecorator(
|
2881
|
+
requestContentLength,
|
2882
|
+
progressEventReducer(asyncDecorator(onUploadProgress))
|
2883
|
+
);
|
2884
|
+
|
2885
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
|
2886
|
+
}
|
2887
|
+
}
|
2888
|
+
|
2889
|
+
if (!utils$1.isString(withCredentials)) {
|
2890
|
+
withCredentials = withCredentials ? 'include' : 'omit';
|
2891
|
+
}
|
2892
|
+
|
2893
|
+
request = new Request(url, {
|
2894
|
+
...fetchOptions,
|
2895
|
+
signal: composedSignal,
|
2896
|
+
method: method.toUpperCase(),
|
2897
|
+
headers: headers.normalize().toJSON(),
|
2898
|
+
body: data,
|
2899
|
+
duplex: "half",
|
2900
|
+
credentials: withCredentials
|
2901
|
+
});
|
2902
|
+
|
2903
|
+
let response = await fetch(request);
|
2904
|
+
|
2905
|
+
const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
2906
|
+
|
2907
|
+
if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
|
2908
|
+
const options = {};
|
2909
|
+
|
2910
|
+
['status', 'statusText', 'headers'].forEach(prop => {
|
2911
|
+
options[prop] = response[prop];
|
2912
|
+
});
|
2913
|
+
|
2914
|
+
const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
2915
|
+
|
2916
|
+
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
2917
|
+
responseContentLength,
|
2918
|
+
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
2919
|
+
) || [];
|
2920
|
+
|
2921
|
+
response = new Response(
|
2922
|
+
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
2923
|
+
flush && flush();
|
2924
|
+
isStreamResponse && onFinish();
|
2925
|
+
}, encodeText),
|
2926
|
+
options
|
2927
|
+
);
|
2928
|
+
}
|
2929
|
+
|
2930
|
+
responseType = responseType || 'text';
|
2931
|
+
|
2932
|
+
let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
|
2933
|
+
|
2934
|
+
!isStreamResponse && onFinish();
|
2935
|
+
|
2936
|
+
stopTimeout && stopTimeout();
|
2937
|
+
|
2938
|
+
return await new Promise((resolve, reject) => {
|
2939
|
+
settle(resolve, reject, {
|
2940
|
+
data: responseData,
|
2941
|
+
headers: AxiosHeaders$1.from(response.headers),
|
2942
|
+
status: response.status,
|
2943
|
+
statusText: response.statusText,
|
2944
|
+
config,
|
2945
|
+
request
|
2946
|
+
});
|
2947
|
+
})
|
2948
|
+
} catch (err) {
|
2949
|
+
onFinish();
|
2950
|
+
|
2951
|
+
if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
|
2952
|
+
throw Object.assign(
|
2953
|
+
new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
|
2954
|
+
{
|
2955
|
+
cause: err.cause || err
|
2956
|
+
}
|
2957
|
+
)
|
2958
|
+
}
|
2959
|
+
|
2960
|
+
throw AxiosError.from(err, err && err.code, config, request);
|
2961
|
+
}
|
2962
|
+
});
|
2963
|
+
|
2410
2964
|
const knownAdapters = {
|
2411
2965
|
http: httpAdapter,
|
2412
|
-
xhr: xhrAdapter
|
2966
|
+
xhr: xhrAdapter,
|
2967
|
+
fetch: fetchAdapter
|
2413
2968
|
};
|
2414
2969
|
|
2415
2970
|
utils$1.forEach(knownAdapters, (fn, value) => {
|
@@ -2553,109 +3108,7 @@ function dispatchRequest(config) {
|
|
2553
3108
|
});
|
2554
3109
|
}
|
2555
3110
|
|
2556
|
-
const
|
2557
|
-
|
2558
|
-
/**
|
2559
|
-
* Config-specific merge-function which creates a new config-object
|
2560
|
-
* by merging two configuration objects together.
|
2561
|
-
*
|
2562
|
-
* @param {Object} config1
|
2563
|
-
* @param {Object} config2
|
2564
|
-
*
|
2565
|
-
* @returns {Object} New object resulting from merging config2 to config1
|
2566
|
-
*/
|
2567
|
-
function mergeConfig(config1, config2) {
|
2568
|
-
// eslint-disable-next-line no-param-reassign
|
2569
|
-
config2 = config2 || {};
|
2570
|
-
const config = {};
|
2571
|
-
|
2572
|
-
function getMergedValue(target, source, caseless) {
|
2573
|
-
if (utils$1.isPlainObject(target) && utils$1.isPlainObject(source)) {
|
2574
|
-
return utils$1.merge.call({caseless}, target, source);
|
2575
|
-
} else if (utils$1.isPlainObject(source)) {
|
2576
|
-
return utils$1.merge({}, source);
|
2577
|
-
} else if (utils$1.isArray(source)) {
|
2578
|
-
return source.slice();
|
2579
|
-
}
|
2580
|
-
return source;
|
2581
|
-
}
|
2582
|
-
|
2583
|
-
// eslint-disable-next-line consistent-return
|
2584
|
-
function mergeDeepProperties(a, b, caseless) {
|
2585
|
-
if (!utils$1.isUndefined(b)) {
|
2586
|
-
return getMergedValue(a, b, caseless);
|
2587
|
-
} else if (!utils$1.isUndefined(a)) {
|
2588
|
-
return getMergedValue(undefined, a, caseless);
|
2589
|
-
}
|
2590
|
-
}
|
2591
|
-
|
2592
|
-
// eslint-disable-next-line consistent-return
|
2593
|
-
function valueFromConfig2(a, b) {
|
2594
|
-
if (!utils$1.isUndefined(b)) {
|
2595
|
-
return getMergedValue(undefined, b);
|
2596
|
-
}
|
2597
|
-
}
|
2598
|
-
|
2599
|
-
// eslint-disable-next-line consistent-return
|
2600
|
-
function defaultToConfig2(a, b) {
|
2601
|
-
if (!utils$1.isUndefined(b)) {
|
2602
|
-
return getMergedValue(undefined, b);
|
2603
|
-
} else if (!utils$1.isUndefined(a)) {
|
2604
|
-
return getMergedValue(undefined, a);
|
2605
|
-
}
|
2606
|
-
}
|
2607
|
-
|
2608
|
-
// eslint-disable-next-line consistent-return
|
2609
|
-
function mergeDirectKeys(a, b, prop) {
|
2610
|
-
if (prop in config2) {
|
2611
|
-
return getMergedValue(a, b);
|
2612
|
-
} else if (prop in config1) {
|
2613
|
-
return getMergedValue(undefined, a);
|
2614
|
-
}
|
2615
|
-
}
|
2616
|
-
|
2617
|
-
const mergeMap = {
|
2618
|
-
url: valueFromConfig2,
|
2619
|
-
method: valueFromConfig2,
|
2620
|
-
data: valueFromConfig2,
|
2621
|
-
baseURL: defaultToConfig2,
|
2622
|
-
transformRequest: defaultToConfig2,
|
2623
|
-
transformResponse: defaultToConfig2,
|
2624
|
-
paramsSerializer: defaultToConfig2,
|
2625
|
-
timeout: defaultToConfig2,
|
2626
|
-
timeoutMessage: defaultToConfig2,
|
2627
|
-
withCredentials: defaultToConfig2,
|
2628
|
-
withXSRFToken: defaultToConfig2,
|
2629
|
-
adapter: defaultToConfig2,
|
2630
|
-
responseType: defaultToConfig2,
|
2631
|
-
xsrfCookieName: defaultToConfig2,
|
2632
|
-
xsrfHeaderName: defaultToConfig2,
|
2633
|
-
onUploadProgress: defaultToConfig2,
|
2634
|
-
onDownloadProgress: defaultToConfig2,
|
2635
|
-
decompress: defaultToConfig2,
|
2636
|
-
maxContentLength: defaultToConfig2,
|
2637
|
-
maxBodyLength: defaultToConfig2,
|
2638
|
-
beforeRedirect: defaultToConfig2,
|
2639
|
-
transport: defaultToConfig2,
|
2640
|
-
httpAgent: defaultToConfig2,
|
2641
|
-
httpsAgent: defaultToConfig2,
|
2642
|
-
cancelToken: defaultToConfig2,
|
2643
|
-
socketPath: defaultToConfig2,
|
2644
|
-
responseEncoding: defaultToConfig2,
|
2645
|
-
validateStatus: mergeDirectKeys,
|
2646
|
-
headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
|
2647
|
-
};
|
2648
|
-
|
2649
|
-
utils$1.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
|
2650
|
-
const merge = mergeMap[prop] || mergeDeepProperties;
|
2651
|
-
const configValue = merge(config1[prop], config2[prop], prop);
|
2652
|
-
(utils$1.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
2653
|
-
});
|
2654
|
-
|
2655
|
-
return config;
|
2656
|
-
}
|
2657
|
-
|
2658
|
-
const VERSION = "1.6.7";
|
3111
|
+
const VERSION = "1.7.3";
|
2659
3112
|
|
2660
3113
|
const validators$1 = {};
|
2661
3114
|
|
@@ -2781,12 +3234,15 @@ class Axios {
|
|
2781
3234
|
|
2782
3235
|
// slice off the Error: ... line
|
2783
3236
|
const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
|
2784
|
-
|
2785
|
-
|
2786
|
-
|
2787
|
-
|
2788
|
-
|
2789
|
-
|
3237
|
+
try {
|
3238
|
+
if (!err.stack) {
|
3239
|
+
err.stack = stack;
|
3240
|
+
// match without the 2 top stack lines
|
3241
|
+
} else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
|
3242
|
+
err.stack += '\n' + stack;
|
3243
|
+
}
|
3244
|
+
} catch (e) {
|
3245
|
+
// ignore the case where "stack" is an un-writable property
|
2790
3246
|
}
|
2791
3247
|
}
|
2792
3248
|
|