mirror of
https://github.com/tenrok/axios.git
synced 2026-06-05 16:42:32 +03:00
chore(release): v1.7.3 (#6521)
Co-authored-by: DigitalBrainJS <12586868+DigitalBrainJS@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
e3c76fc9bd
commit
c6cce43cd9
@@ -1,5 +1,20 @@
|
||||
# Changelog
|
||||
|
||||
## [1.7.3](https://github.com/axios/axios/compare/v1.7.2...v1.7.3) (2024-08-01)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **adapter:** fix progress event emitting; ([#6518](https://github.com/axios/axios/issues/6518)) ([e3c76fc](https://github.com/axios/axios/commit/e3c76fc9bdd03aa4d98afaf211df943e2031453f))
|
||||
* **fetch:** fix withCredentials request config ([#6505](https://github.com/axios/axios/issues/6505)) ([85d4d0e](https://github.com/axios/axios/commit/85d4d0ea0aae91082f04e303dec46510d1b4e787))
|
||||
* **xhr:** return original config on errors from XHR adapter ([#6515](https://github.com/axios/axios/issues/6515)) ([8966ee7](https://github.com/axios/axios/commit/8966ee7ea62ecbd6cfb39a905939bcdab5cf6388))
|
||||
|
||||
### Contributors to this release
|
||||
|
||||
- <img src="https://avatars.githubusercontent.com/u/12586868?v=4&s=18" alt="avatar" width="18"/> [Dmitriy Mozgovoy](https://github.com/DigitalBrainJS "+211/-159 (#6518 #6519 )")
|
||||
- <img src="https://avatars.githubusercontent.com/u/10867286?v=4&s=18" alt="avatar" width="18"/> [Valerii Sidorenko](https://github.com/ValeraS "+3/-3 (#6515 )")
|
||||
- <img src="https://avatars.githubusercontent.com/u/8599535?v=4&s=18" alt="avatar" width="18"/> [prianYu](https://github.com/prianyu "+2/-2 (#6505 )")
|
||||
|
||||
## [1.7.2](https://github.com/axios/axios/compare/v1.7.1...v1.7.2) (2024-05-21)
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "axios",
|
||||
"main": "./dist/axios.js",
|
||||
"version": "1.7.2",
|
||||
"version": "1.7.3",
|
||||
"homepage": "https://axios-http.com",
|
||||
"authors": [
|
||||
"Matt Zabriskie"
|
||||
|
||||
Vendored
+170
-80
@@ -1,4 +1,4 @@
|
||||
// Axios v1.7.2 Copyright (c) 2024 Matt Zabriskie and contributors
|
||||
// Axios v1.7.3 Copyright (c) 2024 Matt Zabriskie and contributors
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
@@ -1320,6 +1320,34 @@
|
||||
var isThenable = function isThenable(thing) {
|
||||
return thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing["catch"]);
|
||||
};
|
||||
|
||||
// original code
|
||||
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
||||
|
||||
var _setImmediate = function (setImmediateSupported, postMessageSupported) {
|
||||
if (setImmediateSupported) {
|
||||
return setImmediate;
|
||||
}
|
||||
return postMessageSupported ? function (token, callbacks) {
|
||||
_global.addEventListener("message", function (_ref5) {
|
||||
var source = _ref5.source,
|
||||
data = _ref5.data;
|
||||
if (source === _global && data === token) {
|
||||
callbacks.length && callbacks.shift()();
|
||||
}
|
||||
}, false);
|
||||
return function (cb) {
|
||||
callbacks.push(cb);
|
||||
_global.postMessage(token, "*");
|
||||
};
|
||||
}("axios@".concat(Math.random()), []) : function (cb) {
|
||||
return setTimeout(cb);
|
||||
};
|
||||
}(typeof setImmediate === 'function', isFunction(_global.postMessage));
|
||||
var asap = typeof queueMicrotask !== 'undefined' ? queueMicrotask.bind(_global) : typeof process !== 'undefined' && process.nextTick || _setImmediate;
|
||||
|
||||
// *********************
|
||||
|
||||
var utils$1 = {
|
||||
isArray: isArray,
|
||||
isArrayBuffer: isArrayBuffer,
|
||||
@@ -1376,7 +1404,9 @@
|
||||
isSpecCompliantForm: isSpecCompliantForm,
|
||||
toJSONObject: toJSONObject,
|
||||
isAsyncFn: isAsyncFn,
|
||||
isThenable: isThenable
|
||||
isThenable: isThenable,
|
||||
setImmediate: _setImmediate,
|
||||
asap: asap
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -2528,30 +2558,43 @@
|
||||
function throttle(fn, freq) {
|
||||
var timestamp = 0;
|
||||
var threshold = 1000 / freq;
|
||||
var timer = null;
|
||||
return function throttled() {
|
||||
var _arguments = arguments;
|
||||
var force = this === true;
|
||||
var now = Date.now();
|
||||
if (force || now - timestamp > threshold) {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
timestamp = now;
|
||||
return fn.apply(null, arguments);
|
||||
var lastArgs;
|
||||
var timer;
|
||||
var invoke = function invoke(args) {
|
||||
var now = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
|
||||
timestamp = now;
|
||||
lastArgs = null;
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
if (!timer) {
|
||||
timer = setTimeout(function () {
|
||||
timer = null;
|
||||
timestamp = Date.now();
|
||||
return fn.apply(null, _arguments);
|
||||
}, threshold - (now - timestamp));
|
||||
fn.apply(null, args);
|
||||
};
|
||||
var throttled = function throttled() {
|
||||
var now = Date.now();
|
||||
var passed = now - timestamp;
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
if (passed >= threshold) {
|
||||
invoke(args, now);
|
||||
} else {
|
||||
lastArgs = args;
|
||||
if (!timer) {
|
||||
timer = setTimeout(function () {
|
||||
timer = null;
|
||||
invoke(lastArgs);
|
||||
}, threshold - passed);
|
||||
}
|
||||
}
|
||||
};
|
||||
var flush = function flush() {
|
||||
return lastArgs && invoke(lastArgs);
|
||||
};
|
||||
return [throttled, flush];
|
||||
}
|
||||
|
||||
var progressEventReducer = (function (listener, isDownloadStream) {
|
||||
var progressEventReducer = function progressEventReducer(listener, isDownloadStream) {
|
||||
var freq = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3;
|
||||
var bytesNotified = 0;
|
||||
var _speedometer = speedometer(50, 250);
|
||||
@@ -2562,7 +2605,7 @@
|
||||
var rate = _speedometer(progressBytes);
|
||||
var inRange = loaded <= total;
|
||||
bytesNotified = loaded;
|
||||
var data = {
|
||||
var data = _defineProperty({
|
||||
loaded: loaded,
|
||||
total: total,
|
||||
progress: total ? loaded / total : undefined,
|
||||
@@ -2571,11 +2614,30 @@
|
||||
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
||||
event: e,
|
||||
lengthComputable: total != null
|
||||
};
|
||||
data[isDownloadStream ? 'download' : 'upload'] = true;
|
||||
}, isDownloadStream ? 'download' : 'upload', true);
|
||||
listener(data);
|
||||
}, freq);
|
||||
});
|
||||
};
|
||||
var progressEventDecorator = function progressEventDecorator(total, throttled) {
|
||||
var lengthComputable = total != null;
|
||||
return [function (loaded) {
|
||||
return throttled[0]({
|
||||
lengthComputable: lengthComputable,
|
||||
total: total,
|
||||
loaded: loaded
|
||||
});
|
||||
}, throttled[1]];
|
||||
};
|
||||
var asyncDecorator = function asyncDecorator(fn) {
|
||||
return function () {
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
return utils$1.asap(function () {
|
||||
return fn.apply(void 0, args);
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
var isURLSameOrigin = platform.hasStandardBrowserEnv ?
|
||||
// Standard browser envs have full support of the APIs needed to test
|
||||
@@ -2861,15 +2923,18 @@
|
||||
var _config = resolveConfig(config);
|
||||
var requestData = _config.data;
|
||||
var requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
|
||||
var responseType = _config.responseType;
|
||||
var responseType = _config.responseType,
|
||||
onUploadProgress = _config.onUploadProgress,
|
||||
onDownloadProgress = _config.onDownloadProgress;
|
||||
var onCanceled;
|
||||
var uploadThrottled, downloadThrottled;
|
||||
var flushUpload, flushDownload;
|
||||
function done() {
|
||||
if (_config.cancelToken) {
|
||||
_config.cancelToken.unsubscribe(onCanceled);
|
||||
}
|
||||
if (_config.signal) {
|
||||
_config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
flushUpload && flushUpload(); // flush events
|
||||
flushDownload && flushDownload(); // flush events
|
||||
|
||||
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
||||
_config.signal && _config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
var request = new XMLHttpRequest();
|
||||
request.open(_config.method.toUpperCase(), _config.url, true);
|
||||
@@ -2930,7 +2995,7 @@
|
||||
if (!request) {
|
||||
return;
|
||||
}
|
||||
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, _config, request));
|
||||
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
@@ -2940,7 +3005,7 @@
|
||||
request.onerror = function handleError() {
|
||||
// Real errors are hidden from us by the browser
|
||||
// onerror should only fire if it's a network error
|
||||
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, _config, request));
|
||||
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
@@ -2953,7 +3018,7 @@
|
||||
if (_config.timeoutErrorMessage) {
|
||||
timeoutErrorMessage = _config.timeoutErrorMessage;
|
||||
}
|
||||
reject(new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, _config, request));
|
||||
reject(new AxiosError(timeoutErrorMessage, transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED, config, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
@@ -2980,13 +3045,22 @@
|
||||
}
|
||||
|
||||
// Handle progress if needed
|
||||
if (typeof _config.onDownloadProgress === 'function') {
|
||||
request.addEventListener('progress', progressEventReducer(_config.onDownloadProgress, true));
|
||||
if (onDownloadProgress) {
|
||||
var _progressEventReducer = progressEventReducer(onDownloadProgress, true);
|
||||
var _progressEventReducer2 = _slicedToArray(_progressEventReducer, 2);
|
||||
downloadThrottled = _progressEventReducer2[0];
|
||||
flushDownload = _progressEventReducer2[1];
|
||||
request.addEventListener('progress', downloadThrottled);
|
||||
}
|
||||
|
||||
// Not all browsers support upload events
|
||||
if (typeof _config.onUploadProgress === 'function' && request.upload) {
|
||||
request.upload.addEventListener('progress', progressEventReducer(_config.onUploadProgress));
|
||||
if (onUploadProgress && request.upload) {
|
||||
var _progressEventReducer3 = progressEventReducer(onUploadProgress);
|
||||
var _progressEventReducer4 = _slicedToArray(_progressEventReducer3, 2);
|
||||
uploadThrottled = _progressEventReducer4[0];
|
||||
flushUpload = _progressEventReducer4[1];
|
||||
request.upload.addEventListener('progress', uploadThrottled);
|
||||
request.upload.addEventListener('loadend', flushUpload);
|
||||
}
|
||||
if (_config.cancelToken || _config.signal) {
|
||||
// Handle cancellation
|
||||
@@ -3171,40 +3245,57 @@
|
||||
var trackStream = function trackStream(stream, chunkSize, onProgress, onFinish, encode) {
|
||||
var iterator = readBytes(stream, chunkSize, encode);
|
||||
var bytes = 0;
|
||||
var done;
|
||||
var _onFinish = function _onFinish(e) {
|
||||
if (!done) {
|
||||
done = true;
|
||||
onFinish && onFinish(e);
|
||||
}
|
||||
};
|
||||
return new ReadableStream({
|
||||
type: 'bytes',
|
||||
pull: function pull(controller) {
|
||||
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
||||
var _yield$iterator$next, done, value, len;
|
||||
var _yield$iterator$next, _done, value, len, loadedBytes;
|
||||
return _regeneratorRuntime().wrap(function _callee2$(_context3) {
|
||||
while (1) switch (_context3.prev = _context3.next) {
|
||||
case 0:
|
||||
_context3.next = 2;
|
||||
_context3.prev = 0;
|
||||
_context3.next = 3;
|
||||
return iterator.next();
|
||||
case 2:
|
||||
case 3:
|
||||
_yield$iterator$next = _context3.sent;
|
||||
done = _yield$iterator$next.done;
|
||||
_done = _yield$iterator$next.done;
|
||||
value = _yield$iterator$next.value;
|
||||
if (!done) {
|
||||
_context3.next = 9;
|
||||
if (!_done) {
|
||||
_context3.next = 10;
|
||||
break;
|
||||
}
|
||||
_onFinish();
|
||||
controller.close();
|
||||
onFinish();
|
||||
return _context3.abrupt("return");
|
||||
case 9:
|
||||
case 10:
|
||||
len = value.byteLength;
|
||||
onProgress && onProgress(bytes += len);
|
||||
if (onProgress) {
|
||||
loadedBytes = bytes += len;
|
||||
onProgress(loadedBytes);
|
||||
}
|
||||
controller.enqueue(new Uint8Array(value));
|
||||
case 12:
|
||||
_context3.next = 19;
|
||||
break;
|
||||
case 15:
|
||||
_context3.prev = 15;
|
||||
_context3.t0 = _context3["catch"](0);
|
||||
_onFinish(_context3.t0);
|
||||
throw _context3.t0;
|
||||
case 19:
|
||||
case "end":
|
||||
return _context3.stop();
|
||||
}
|
||||
}, _callee2);
|
||||
}, _callee2, null, [[0, 15]]);
|
||||
}))();
|
||||
},
|
||||
cancel: function cancel(reason) {
|
||||
onFinish(reason);
|
||||
_onFinish(reason);
|
||||
return iterator["return"]();
|
||||
}
|
||||
}, {
|
||||
@@ -3212,18 +3303,6 @@
|
||||
});
|
||||
};
|
||||
|
||||
var fetchProgressDecorator = function fetchProgressDecorator(total, fn) {
|
||||
var lengthComputable = total != null;
|
||||
return function (loaded) {
|
||||
return setTimeout(function () {
|
||||
return fn({
|
||||
lengthComputable: lengthComputable,
|
||||
total: total,
|
||||
loaded: loaded
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
var isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
|
||||
var isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
|
||||
|
||||
@@ -3253,7 +3332,17 @@
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}()));
|
||||
var supportsRequestStream = isReadableStreamSupported && function () {
|
||||
var test = function test(fn) {
|
||||
try {
|
||||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
||||
args[_key - 1] = arguments[_key];
|
||||
}
|
||||
return !!fn.apply(void 0, args);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
var supportsRequestStream = isReadableStreamSupported && test(function () {
|
||||
var duplexAccessed = false;
|
||||
var hasContentType = new Request(platform.origin, {
|
||||
body: new ReadableStream(),
|
||||
@@ -3264,15 +3353,11 @@
|
||||
}
|
||||
}).headers.has('Content-Type');
|
||||
return duplexAccessed && !hasContentType;
|
||||
}();
|
||||
});
|
||||
var DEFAULT_CHUNK_SIZE = 64 * 1024;
|
||||
var supportsResponseStream = isReadableStreamSupported && !!function () {
|
||||
try {
|
||||
return utils$1.isReadableStream(new Response('').body);
|
||||
} catch (err) {
|
||||
// return undefined
|
||||
}
|
||||
}();
|
||||
var supportsResponseStream = isReadableStreamSupported && test(function () {
|
||||
return utils$1.isReadableStream(new Response('').body);
|
||||
});
|
||||
var resolvers = {
|
||||
stream: supportsResponseStream && function (res) {
|
||||
return res.body;
|
||||
@@ -3313,7 +3398,7 @@
|
||||
case 7:
|
||||
return _context2.abrupt("return", _context2.sent.byteLength);
|
||||
case 8:
|
||||
if (!utils$1.isArrayBufferView(body)) {
|
||||
if (!(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body))) {
|
||||
_context2.next = 10;
|
||||
break;
|
||||
}
|
||||
@@ -3360,7 +3445,7 @@
|
||||
}();
|
||||
var fetchAdapter = isFetchSupported && ( /*#__PURE__*/function () {
|
||||
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config) {
|
||||
var _resolveConfig, url, method, data, signal, cancelToken, timeout, onDownloadProgress, onUploadProgress, responseType, headers, _resolveConfig$withCr, withCredentials, fetchOptions, _ref5, _ref6, composedSignal, stopTimeout, finished, request, onFinish, requestContentLength, _request, contentTypeHeader, response, isStreamResponse, options, responseContentLength, responseData;
|
||||
var _resolveConfig, url, method, data, signal, cancelToken, timeout, onDownloadProgress, onUploadProgress, responseType, headers, _resolveConfig$withCr, withCredentials, fetchOptions, _ref5, _ref6, composedSignal, stopTimeout, finished, request, onFinish, requestContentLength, _request, contentTypeHeader, _progressEventDecorat, _progressEventDecorat2, onProgress, flush, response, isStreamResponse, options, responseContentLength, _ref7, _ref8, _onProgress, _flush, responseData;
|
||||
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
||||
while (1) switch (_context4.prev = _context4.next) {
|
||||
case 0:
|
||||
@@ -3398,11 +3483,12 @@
|
||||
headers.setContentType(contentTypeHeader);
|
||||
}
|
||||
if (_request.body) {
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(requestContentLength, progressEventReducer(onUploadProgress)), null, encodeText);
|
||||
_progressEventDecorat = progressEventDecorator(requestContentLength, progressEventReducer(asyncDecorator(onUploadProgress))), _progressEventDecorat2 = _slicedToArray(_progressEventDecorat, 2), onProgress = _progressEventDecorat2[0], flush = _progressEventDecorat2[1];
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
|
||||
}
|
||||
case 15:
|
||||
if (!utils$1.isString(withCredentials)) {
|
||||
withCredentials = withCredentials ? 'cors' : 'omit';
|
||||
withCredentials = withCredentials ? 'include' : 'omit';
|
||||
}
|
||||
request = new Request(url, _objectSpread2(_objectSpread2({}, fetchOptions), {}, {
|
||||
signal: composedSignal,
|
||||
@@ -3410,7 +3496,7 @@
|
||||
headers: headers.normalize().toJSON(),
|
||||
body: data,
|
||||
duplex: "half",
|
||||
withCredentials: withCredentials
|
||||
credentials: withCredentials
|
||||
}));
|
||||
_context4.next = 19;
|
||||
return fetch(request);
|
||||
@@ -3423,7 +3509,11 @@
|
||||
options[prop] = response[prop];
|
||||
});
|
||||
responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
||||
response = new Response(trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator(responseContentLength, progressEventReducer(onDownloadProgress, true)), isStreamResponse && onFinish, encodeText), options);
|
||||
_ref7 = onDownloadProgress && progressEventDecorator(responseContentLength, progressEventReducer(asyncDecorator(onDownloadProgress), true)) || [], _ref8 = _slicedToArray(_ref7, 2), _onProgress = _ref8[0], _flush = _ref8[1];
|
||||
response = new Response(trackStream(response.body, DEFAULT_CHUNK_SIZE, _onProgress, function () {
|
||||
_flush && _flush();
|
||||
isStreamResponse && onFinish();
|
||||
}, encodeText), options);
|
||||
}
|
||||
responseType = responseType || 'text';
|
||||
_context4.next = 25;
|
||||
@@ -3586,7 +3676,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
var VERSION = "1.7.2";
|
||||
var VERSION = "1.7.3";
|
||||
|
||||
var validators$1 = {};
|
||||
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+156
-80
@@ -1,4 +1,4 @@
|
||||
// Axios v1.7.2 Copyright (c) 2024 Matt Zabriskie and contributors
|
||||
// Axios v1.7.3 Copyright (c) 2024 Matt Zabriskie and contributors
|
||||
'use strict';
|
||||
|
||||
function bind(fn, thisArg) {
|
||||
@@ -674,6 +674,36 @@ const isAsyncFn = kindOfTest('AsyncFunction');
|
||||
const isThenable = (thing) =>
|
||||
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
||||
|
||||
// original code
|
||||
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
||||
|
||||
const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
||||
if (setImmediateSupported) {
|
||||
return setImmediate;
|
||||
}
|
||||
|
||||
return postMessageSupported ? ((token, callbacks) => {
|
||||
_global.addEventListener("message", ({source, data}) => {
|
||||
if (source === _global && data === token) {
|
||||
callbacks.length && callbacks.shift()();
|
||||
}
|
||||
}, false);
|
||||
|
||||
return (cb) => {
|
||||
callbacks.push(cb);
|
||||
_global.postMessage(token, "*");
|
||||
}
|
||||
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
||||
})(
|
||||
typeof setImmediate === 'function',
|
||||
isFunction(_global.postMessage)
|
||||
);
|
||||
|
||||
const asap = typeof queueMicrotask !== 'undefined' ?
|
||||
queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
|
||||
|
||||
// *********************
|
||||
|
||||
var utils$1 = {
|
||||
isArray,
|
||||
isArrayBuffer,
|
||||
@@ -729,7 +759,9 @@ var utils$1 = {
|
||||
isSpecCompliantForm,
|
||||
toJSONObject,
|
||||
isAsyncFn,
|
||||
isThenable
|
||||
isThenable,
|
||||
setImmediate: _setImmediate,
|
||||
asap
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -2040,31 +2072,42 @@ function speedometer(samplesCount, min) {
|
||||
*/
|
||||
function throttle(fn, freq) {
|
||||
let timestamp = 0;
|
||||
const threshold = 1000 / freq;
|
||||
let timer = null;
|
||||
return function throttled() {
|
||||
const force = this === true;
|
||||
let threshold = 1000 / freq;
|
||||
let lastArgs;
|
||||
let timer;
|
||||
|
||||
const now = Date.now();
|
||||
if (force || now - timestamp > threshold) {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
timestamp = now;
|
||||
return fn.apply(null, arguments);
|
||||
const invoke = (args, now = Date.now()) => {
|
||||
timestamp = now;
|
||||
lastArgs = null;
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
if (!timer) {
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
timestamp = Date.now();
|
||||
return fn.apply(null, arguments);
|
||||
}, threshold - (now - timestamp));
|
||||
fn.apply(null, args);
|
||||
};
|
||||
|
||||
const throttled = (...args) => {
|
||||
const now = Date.now();
|
||||
const passed = now - timestamp;
|
||||
if ( passed >= threshold) {
|
||||
invoke(args, now);
|
||||
} else {
|
||||
lastArgs = args;
|
||||
if (!timer) {
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
invoke(lastArgs);
|
||||
}, threshold - passed);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const flush = () => lastArgs && invoke(lastArgs);
|
||||
|
||||
return [throttled, flush];
|
||||
}
|
||||
|
||||
var progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
||||
const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
||||
let bytesNotified = 0;
|
||||
const _speedometer = speedometer(50, 250);
|
||||
|
||||
@@ -2085,15 +2128,26 @@ var progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
||||
rate: rate ? rate : undefined,
|
||||
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
||||
event: e,
|
||||
lengthComputable: total != null
|
||||
lengthComputable: total != null,
|
||||
[isDownloadStream ? 'download' : 'upload']: true
|
||||
};
|
||||
|
||||
data[isDownloadStream ? 'download' : 'upload'] = true;
|
||||
|
||||
listener(data);
|
||||
}, freq);
|
||||
};
|
||||
|
||||
const progressEventDecorator = (total, throttled) => {
|
||||
const lengthComputable = total != null;
|
||||
|
||||
return [(loaded) => throttled[0]({
|
||||
lengthComputable,
|
||||
total,
|
||||
loaded
|
||||
}), throttled[1]];
|
||||
};
|
||||
|
||||
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
||||
|
||||
var isURLSameOrigin = platform.hasStandardBrowserEnv ?
|
||||
|
||||
// Standard browser envs have full support of the APIs needed to test
|
||||
@@ -2398,16 +2452,18 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
const _config = resolveConfig(config);
|
||||
let requestData = _config.data;
|
||||
const requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
|
||||
let {responseType} = _config;
|
||||
let {responseType, onUploadProgress, onDownloadProgress} = _config;
|
||||
let onCanceled;
|
||||
function done() {
|
||||
if (_config.cancelToken) {
|
||||
_config.cancelToken.unsubscribe(onCanceled);
|
||||
}
|
||||
let uploadThrottled, downloadThrottled;
|
||||
let flushUpload, flushDownload;
|
||||
|
||||
if (_config.signal) {
|
||||
_config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
function done() {
|
||||
flushUpload && flushUpload(); // flush events
|
||||
flushDownload && flushDownload(); // flush events
|
||||
|
||||
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
||||
|
||||
_config.signal && _config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
|
||||
let request = new XMLHttpRequest();
|
||||
@@ -2477,7 +2533,7 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
return;
|
||||
}
|
||||
|
||||
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, _config, request));
|
||||
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
@@ -2487,7 +2543,7 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
request.onerror = function handleError() {
|
||||
// Real errors are hidden from us by the browser
|
||||
// onerror should only fire if it's a network error
|
||||
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, _config, request));
|
||||
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
@@ -2503,7 +2559,7 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
reject(new AxiosError(
|
||||
timeoutErrorMessage,
|
||||
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
||||
_config,
|
||||
config,
|
||||
request));
|
||||
|
||||
// Clean up request
|
||||
@@ -2531,13 +2587,18 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
}
|
||||
|
||||
// Handle progress if needed
|
||||
if (typeof _config.onDownloadProgress === 'function') {
|
||||
request.addEventListener('progress', progressEventReducer(_config.onDownloadProgress, true));
|
||||
if (onDownloadProgress) {
|
||||
([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
|
||||
request.addEventListener('progress', downloadThrottled);
|
||||
}
|
||||
|
||||
// Not all browsers support upload events
|
||||
if (typeof _config.onUploadProgress === 'function' && request.upload) {
|
||||
request.upload.addEventListener('progress', progressEventReducer(_config.onUploadProgress));
|
||||
if (onUploadProgress && request.upload) {
|
||||
([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
|
||||
|
||||
request.upload.addEventListener('progress', uploadThrottled);
|
||||
|
||||
request.upload.addEventListener('loadend', flushUpload);
|
||||
}
|
||||
|
||||
if (_config.cancelToken || _config.signal) {
|
||||
@@ -2643,25 +2704,38 @@ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
||||
const iterator = readBytes(stream, chunkSize, encode);
|
||||
|
||||
let bytes = 0;
|
||||
let done;
|
||||
let _onFinish = (e) => {
|
||||
if (!done) {
|
||||
done = true;
|
||||
onFinish && onFinish(e);
|
||||
}
|
||||
};
|
||||
|
||||
return new ReadableStream({
|
||||
type: 'bytes',
|
||||
|
||||
async pull(controller) {
|
||||
const {done, value} = await iterator.next();
|
||||
try {
|
||||
const {done, value} = await iterator.next();
|
||||
|
||||
if (done) {
|
||||
controller.close();
|
||||
onFinish();
|
||||
return;
|
||||
if (done) {
|
||||
_onFinish();
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
|
||||
let len = value.byteLength;
|
||||
if (onProgress) {
|
||||
let loadedBytes = bytes += len;
|
||||
onProgress(loadedBytes);
|
||||
}
|
||||
controller.enqueue(new Uint8Array(value));
|
||||
} catch (err) {
|
||||
_onFinish(err);
|
||||
throw err;
|
||||
}
|
||||
|
||||
let len = value.byteLength;
|
||||
onProgress && onProgress(bytes += len);
|
||||
controller.enqueue(new Uint8Array(value));
|
||||
},
|
||||
cancel(reason) {
|
||||
onFinish(reason);
|
||||
_onFinish(reason);
|
||||
return iterator.return();
|
||||
}
|
||||
}, {
|
||||
@@ -2669,15 +2743,6 @@ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
||||
})
|
||||
};
|
||||
|
||||
const fetchProgressDecorator = (total, fn) => {
|
||||
const lengthComputable = total != null;
|
||||
return (loaded) => setTimeout(() => fn({
|
||||
lengthComputable,
|
||||
total,
|
||||
loaded
|
||||
}));
|
||||
};
|
||||
|
||||
const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
|
||||
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
|
||||
|
||||
@@ -2687,7 +2752,15 @@ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
||||
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
||||
);
|
||||
|
||||
const supportsRequestStream = isReadableStreamSupported && (() => {
|
||||
const test = (fn, ...args) => {
|
||||
try {
|
||||
return !!fn(...args);
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
};
|
||||
|
||||
const supportsRequestStream = isReadableStreamSupported && test(() => {
|
||||
let duplexAccessed = false;
|
||||
|
||||
const hasContentType = new Request(platform.origin, {
|
||||
@@ -2700,17 +2773,13 @@ const supportsRequestStream = isReadableStreamSupported && (() => {
|
||||
}).headers.has('Content-Type');
|
||||
|
||||
return duplexAccessed && !hasContentType;
|
||||
})();
|
||||
});
|
||||
|
||||
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
||||
|
||||
const supportsResponseStream = isReadableStreamSupported && !!(()=> {
|
||||
try {
|
||||
return utils$1.isReadableStream(new Response('').body);
|
||||
} catch(err) {
|
||||
// return undefined
|
||||
}
|
||||
})();
|
||||
const supportsResponseStream = isReadableStreamSupported &&
|
||||
test(() => utils$1.isReadableStream(new Response('').body));
|
||||
|
||||
|
||||
const resolvers = {
|
||||
stream: supportsResponseStream && ((res) => res.body)
|
||||
@@ -2738,7 +2807,7 @@ const getBodyLength = async (body) => {
|
||||
return (await new Request(body).arrayBuffer()).byteLength;
|
||||
}
|
||||
|
||||
if(utils$1.isArrayBufferView(body)) {
|
||||
if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
||||
return body.byteLength;
|
||||
}
|
||||
|
||||
@@ -2808,15 +2877,17 @@ var fetchAdapter = isFetchSupported && (async (config) => {
|
||||
}
|
||||
|
||||
if (_request.body) {
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(
|
||||
const [onProgress, flush] = progressEventDecorator(
|
||||
requestContentLength,
|
||||
progressEventReducer(onUploadProgress)
|
||||
), null, encodeText);
|
||||
progressEventReducer(asyncDecorator(onUploadProgress))
|
||||
);
|
||||
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
|
||||
}
|
||||
}
|
||||
|
||||
if (!utils$1.isString(withCredentials)) {
|
||||
withCredentials = withCredentials ? 'cors' : 'omit';
|
||||
withCredentials = withCredentials ? 'include' : 'omit';
|
||||
}
|
||||
|
||||
request = new Request(url, {
|
||||
@@ -2826,7 +2897,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
|
||||
headers: headers.normalize().toJSON(),
|
||||
body: data,
|
||||
duplex: "half",
|
||||
withCredentials
|
||||
credentials: withCredentials
|
||||
});
|
||||
|
||||
let response = await fetch(request);
|
||||
@@ -2842,11 +2913,16 @@ var fetchAdapter = isFetchSupported && (async (config) => {
|
||||
|
||||
const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
||||
|
||||
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
||||
responseContentLength,
|
||||
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
||||
) || [];
|
||||
|
||||
response = new Response(
|
||||
trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator(
|
||||
responseContentLength,
|
||||
progressEventReducer(onDownloadProgress, true)
|
||||
), isStreamResponse && onFinish, encodeText),
|
||||
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
||||
flush && flush();
|
||||
isStreamResponse && onFinish();
|
||||
}, encodeText),
|
||||
options
|
||||
);
|
||||
}
|
||||
@@ -3032,7 +3108,7 @@ function dispatchRequest(config) {
|
||||
});
|
||||
}
|
||||
|
||||
const VERSION = "1.7.2";
|
||||
const VERSION = "1.7.3";
|
||||
|
||||
const validators$1 = {};
|
||||
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+155
-79
@@ -1,4 +1,4 @@
|
||||
// Axios v1.7.2 Copyright (c) 2024 Matt Zabriskie and contributors
|
||||
// Axios v1.7.3 Copyright (c) 2024 Matt Zabriskie and contributors
|
||||
function bind(fn, thisArg) {
|
||||
return function wrap() {
|
||||
return fn.apply(thisArg, arguments);
|
||||
@@ -672,6 +672,36 @@ const isAsyncFn = kindOfTest('AsyncFunction');
|
||||
const isThenable = (thing) =>
|
||||
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
||||
|
||||
// original code
|
||||
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
||||
|
||||
const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
||||
if (setImmediateSupported) {
|
||||
return setImmediate;
|
||||
}
|
||||
|
||||
return postMessageSupported ? ((token, callbacks) => {
|
||||
_global.addEventListener("message", ({source, data}) => {
|
||||
if (source === _global && data === token) {
|
||||
callbacks.length && callbacks.shift()();
|
||||
}
|
||||
}, false);
|
||||
|
||||
return (cb) => {
|
||||
callbacks.push(cb);
|
||||
_global.postMessage(token, "*");
|
||||
}
|
||||
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
||||
})(
|
||||
typeof setImmediate === 'function',
|
||||
isFunction(_global.postMessage)
|
||||
);
|
||||
|
||||
const asap = typeof queueMicrotask !== 'undefined' ?
|
||||
queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
|
||||
|
||||
// *********************
|
||||
|
||||
const utils$1 = {
|
||||
isArray,
|
||||
isArrayBuffer,
|
||||
@@ -727,7 +757,9 @@ const utils$1 = {
|
||||
isSpecCompliantForm,
|
||||
toJSONObject,
|
||||
isAsyncFn,
|
||||
isThenable
|
||||
isThenable,
|
||||
setImmediate: _setImmediate,
|
||||
asap
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -2038,28 +2070,39 @@ function speedometer(samplesCount, min) {
|
||||
*/
|
||||
function throttle(fn, freq) {
|
||||
let timestamp = 0;
|
||||
const threshold = 1000 / freq;
|
||||
let timer = null;
|
||||
return function throttled() {
|
||||
const force = this === true;
|
||||
let threshold = 1000 / freq;
|
||||
let lastArgs;
|
||||
let timer;
|
||||
|
||||
const now = Date.now();
|
||||
if (force || now - timestamp > threshold) {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
timestamp = now;
|
||||
return fn.apply(null, arguments);
|
||||
const invoke = (args, now = Date.now()) => {
|
||||
timestamp = now;
|
||||
lastArgs = null;
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
if (!timer) {
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
timestamp = Date.now();
|
||||
return fn.apply(null, arguments);
|
||||
}, threshold - (now - timestamp));
|
||||
fn.apply(null, args);
|
||||
};
|
||||
|
||||
const throttled = (...args) => {
|
||||
const now = Date.now();
|
||||
const passed = now - timestamp;
|
||||
if ( passed >= threshold) {
|
||||
invoke(args, now);
|
||||
} else {
|
||||
lastArgs = args;
|
||||
if (!timer) {
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
invoke(lastArgs);
|
||||
}, threshold - passed);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const flush = () => lastArgs && invoke(lastArgs);
|
||||
|
||||
return [throttled, flush];
|
||||
}
|
||||
|
||||
const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
||||
@@ -2083,15 +2126,26 @@ const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
||||
rate: rate ? rate : undefined,
|
||||
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
||||
event: e,
|
||||
lengthComputable: total != null
|
||||
lengthComputable: total != null,
|
||||
[isDownloadStream ? 'download' : 'upload']: true
|
||||
};
|
||||
|
||||
data[isDownloadStream ? 'download' : 'upload'] = true;
|
||||
|
||||
listener(data);
|
||||
}, freq);
|
||||
};
|
||||
|
||||
const progressEventDecorator = (total, throttled) => {
|
||||
const lengthComputable = total != null;
|
||||
|
||||
return [(loaded) => throttled[0]({
|
||||
lengthComputable,
|
||||
total,
|
||||
loaded
|
||||
}), throttled[1]];
|
||||
};
|
||||
|
||||
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
||||
|
||||
const isURLSameOrigin = platform.hasStandardBrowserEnv ?
|
||||
|
||||
// Standard browser envs have full support of the APIs needed to test
|
||||
@@ -2396,16 +2450,18 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
const _config = resolveConfig(config);
|
||||
let requestData = _config.data;
|
||||
const requestHeaders = AxiosHeaders$2.from(_config.headers).normalize();
|
||||
let {responseType} = _config;
|
||||
let {responseType, onUploadProgress, onDownloadProgress} = _config;
|
||||
let onCanceled;
|
||||
function done() {
|
||||
if (_config.cancelToken) {
|
||||
_config.cancelToken.unsubscribe(onCanceled);
|
||||
}
|
||||
let uploadThrottled, downloadThrottled;
|
||||
let flushUpload, flushDownload;
|
||||
|
||||
if (_config.signal) {
|
||||
_config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
function done() {
|
||||
flushUpload && flushUpload(); // flush events
|
||||
flushDownload && flushDownload(); // flush events
|
||||
|
||||
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
||||
|
||||
_config.signal && _config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
|
||||
let request = new XMLHttpRequest();
|
||||
@@ -2475,7 +2531,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
return;
|
||||
}
|
||||
|
||||
reject(new AxiosError$1('Request aborted', AxiosError$1.ECONNABORTED, _config, request));
|
||||
reject(new AxiosError$1('Request aborted', AxiosError$1.ECONNABORTED, config, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
@@ -2485,7 +2541,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
request.onerror = function handleError() {
|
||||
// Real errors are hidden from us by the browser
|
||||
// onerror should only fire if it's a network error
|
||||
reject(new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, _config, request));
|
||||
reject(new AxiosError$1('Network Error', AxiosError$1.ERR_NETWORK, config, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
@@ -2501,7 +2557,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
reject(new AxiosError$1(
|
||||
timeoutErrorMessage,
|
||||
transitional.clarifyTimeoutError ? AxiosError$1.ETIMEDOUT : AxiosError$1.ECONNABORTED,
|
||||
_config,
|
||||
config,
|
||||
request));
|
||||
|
||||
// Clean up request
|
||||
@@ -2529,13 +2585,18 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
}
|
||||
|
||||
// Handle progress if needed
|
||||
if (typeof _config.onDownloadProgress === 'function') {
|
||||
request.addEventListener('progress', progressEventReducer(_config.onDownloadProgress, true));
|
||||
if (onDownloadProgress) {
|
||||
([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
|
||||
request.addEventListener('progress', downloadThrottled);
|
||||
}
|
||||
|
||||
// Not all browsers support upload events
|
||||
if (typeof _config.onUploadProgress === 'function' && request.upload) {
|
||||
request.upload.addEventListener('progress', progressEventReducer(_config.onUploadProgress));
|
||||
if (onUploadProgress && request.upload) {
|
||||
([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
|
||||
|
||||
request.upload.addEventListener('progress', uploadThrottled);
|
||||
|
||||
request.upload.addEventListener('loadend', flushUpload);
|
||||
}
|
||||
|
||||
if (_config.cancelToken || _config.signal) {
|
||||
@@ -2641,25 +2702,38 @@ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
||||
const iterator = readBytes(stream, chunkSize, encode);
|
||||
|
||||
let bytes = 0;
|
||||
let done;
|
||||
let _onFinish = (e) => {
|
||||
if (!done) {
|
||||
done = true;
|
||||
onFinish && onFinish(e);
|
||||
}
|
||||
};
|
||||
|
||||
return new ReadableStream({
|
||||
type: 'bytes',
|
||||
|
||||
async pull(controller) {
|
||||
const {done, value} = await iterator.next();
|
||||
try {
|
||||
const {done, value} = await iterator.next();
|
||||
|
||||
if (done) {
|
||||
controller.close();
|
||||
onFinish();
|
||||
return;
|
||||
if (done) {
|
||||
_onFinish();
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
|
||||
let len = value.byteLength;
|
||||
if (onProgress) {
|
||||
let loadedBytes = bytes += len;
|
||||
onProgress(loadedBytes);
|
||||
}
|
||||
controller.enqueue(new Uint8Array(value));
|
||||
} catch (err) {
|
||||
_onFinish(err);
|
||||
throw err;
|
||||
}
|
||||
|
||||
let len = value.byteLength;
|
||||
onProgress && onProgress(bytes += len);
|
||||
controller.enqueue(new Uint8Array(value));
|
||||
},
|
||||
cancel(reason) {
|
||||
onFinish(reason);
|
||||
_onFinish(reason);
|
||||
return iterator.return();
|
||||
}
|
||||
}, {
|
||||
@@ -2667,15 +2741,6 @@ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
||||
})
|
||||
};
|
||||
|
||||
const fetchProgressDecorator = (total, fn) => {
|
||||
const lengthComputable = total != null;
|
||||
return (loaded) => setTimeout(() => fn({
|
||||
lengthComputable,
|
||||
total,
|
||||
loaded
|
||||
}));
|
||||
};
|
||||
|
||||
const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
|
||||
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
|
||||
|
||||
@@ -2685,7 +2750,15 @@ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
||||
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
||||
);
|
||||
|
||||
const supportsRequestStream = isReadableStreamSupported && (() => {
|
||||
const test = (fn, ...args) => {
|
||||
try {
|
||||
return !!fn(...args);
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
};
|
||||
|
||||
const supportsRequestStream = isReadableStreamSupported && test(() => {
|
||||
let duplexAccessed = false;
|
||||
|
||||
const hasContentType = new Request(platform.origin, {
|
||||
@@ -2698,17 +2771,13 @@ const supportsRequestStream = isReadableStreamSupported && (() => {
|
||||
}).headers.has('Content-Type');
|
||||
|
||||
return duplexAccessed && !hasContentType;
|
||||
})();
|
||||
});
|
||||
|
||||
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
||||
|
||||
const supportsResponseStream = isReadableStreamSupported && !!(()=> {
|
||||
try {
|
||||
return utils$1.isReadableStream(new Response('').body);
|
||||
} catch(err) {
|
||||
// return undefined
|
||||
}
|
||||
})();
|
||||
const supportsResponseStream = isReadableStreamSupported &&
|
||||
test(() => utils$1.isReadableStream(new Response('').body));
|
||||
|
||||
|
||||
const resolvers = {
|
||||
stream: supportsResponseStream && ((res) => res.body)
|
||||
@@ -2736,7 +2805,7 @@ const getBodyLength = async (body) => {
|
||||
return (await new Request(body).arrayBuffer()).byteLength;
|
||||
}
|
||||
|
||||
if(utils$1.isArrayBufferView(body)) {
|
||||
if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
||||
return body.byteLength;
|
||||
}
|
||||
|
||||
@@ -2806,15 +2875,17 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
||||
}
|
||||
|
||||
if (_request.body) {
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(
|
||||
const [onProgress, flush] = progressEventDecorator(
|
||||
requestContentLength,
|
||||
progressEventReducer(onUploadProgress)
|
||||
), null, encodeText);
|
||||
progressEventReducer(asyncDecorator(onUploadProgress))
|
||||
);
|
||||
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
|
||||
}
|
||||
}
|
||||
|
||||
if (!utils$1.isString(withCredentials)) {
|
||||
withCredentials = withCredentials ? 'cors' : 'omit';
|
||||
withCredentials = withCredentials ? 'include' : 'omit';
|
||||
}
|
||||
|
||||
request = new Request(url, {
|
||||
@@ -2824,7 +2895,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
||||
headers: headers.normalize().toJSON(),
|
||||
body: data,
|
||||
duplex: "half",
|
||||
withCredentials
|
||||
credentials: withCredentials
|
||||
});
|
||||
|
||||
let response = await fetch(request);
|
||||
@@ -2840,11 +2911,16 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
||||
|
||||
const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
||||
|
||||
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
||||
responseContentLength,
|
||||
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
||||
) || [];
|
||||
|
||||
response = new Response(
|
||||
trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator(
|
||||
responseContentLength,
|
||||
progressEventReducer(onDownloadProgress, true)
|
||||
), isStreamResponse && onFinish, encodeText),
|
||||
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
||||
flush && flush();
|
||||
isStreamResponse && onFinish();
|
||||
}, encodeText),
|
||||
options
|
||||
);
|
||||
}
|
||||
@@ -3030,7 +3106,7 @@ function dispatchRequest(config) {
|
||||
});
|
||||
}
|
||||
|
||||
const VERSION$1 = "1.7.2";
|
||||
const VERSION$1 = "1.7.3";
|
||||
|
||||
const validators$1 = {};
|
||||
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+276
-238
@@ -1,4 +1,4 @@
|
||||
// Axios v1.7.2 Copyright (c) 2024 Matt Zabriskie and contributors
|
||||
// Axios v1.7.3 Copyright (c) 2024 Matt Zabriskie and contributors
|
||||
'use strict';
|
||||
|
||||
const FormData$1 = require('form-data');
|
||||
@@ -696,6 +696,36 @@ const isAsyncFn = kindOfTest('AsyncFunction');
|
||||
const isThenable = (thing) =>
|
||||
thing && (isObject(thing) || isFunction(thing)) && isFunction(thing.then) && isFunction(thing.catch);
|
||||
|
||||
// original code
|
||||
// https://github.com/DigitalBrainJS/AxiosPromise/blob/16deab13710ec09779922131f3fa5954320f83ab/lib/utils.js#L11-L34
|
||||
|
||||
const _setImmediate = ((setImmediateSupported, postMessageSupported) => {
|
||||
if (setImmediateSupported) {
|
||||
return setImmediate;
|
||||
}
|
||||
|
||||
return postMessageSupported ? ((token, callbacks) => {
|
||||
_global.addEventListener("message", ({source, data}) => {
|
||||
if (source === _global && data === token) {
|
||||
callbacks.length && callbacks.shift()();
|
||||
}
|
||||
}, false);
|
||||
|
||||
return (cb) => {
|
||||
callbacks.push(cb);
|
||||
_global.postMessage(token, "*");
|
||||
}
|
||||
})(`axios@${Math.random()}`, []) : (cb) => setTimeout(cb);
|
||||
})(
|
||||
typeof setImmediate === 'function',
|
||||
isFunction(_global.postMessage)
|
||||
);
|
||||
|
||||
const asap = typeof queueMicrotask !== 'undefined' ?
|
||||
queueMicrotask.bind(_global) : ( typeof process !== 'undefined' && process.nextTick || _setImmediate);
|
||||
|
||||
// *********************
|
||||
|
||||
const utils$1 = {
|
||||
isArray,
|
||||
isArrayBuffer,
|
||||
@@ -751,7 +781,9 @@ const utils$1 = {
|
||||
isSpecCompliantForm,
|
||||
toJSONObject,
|
||||
isAsyncFn,
|
||||
isThenable
|
||||
isThenable,
|
||||
setImmediate: _setImmediate,
|
||||
asap
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -2035,7 +2067,7 @@ function buildFullPath(baseURL, requestedURL) {
|
||||
return requestedURL;
|
||||
}
|
||||
|
||||
const VERSION = "1.7.2";
|
||||
const VERSION = "1.7.3";
|
||||
|
||||
function parseProtocol(url) {
|
||||
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
||||
@@ -2090,90 +2122,6 @@ function fromDataURI(uri, asBlob, options) {
|
||||
throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throttle decorator
|
||||
* @param {Function} fn
|
||||
* @param {Number} freq
|
||||
* @return {Function}
|
||||
*/
|
||||
function throttle(fn, freq) {
|
||||
let timestamp = 0;
|
||||
const threshold = 1000 / freq;
|
||||
let timer = null;
|
||||
return function throttled() {
|
||||
const force = this === true;
|
||||
|
||||
const now = Date.now();
|
||||
if (force || now - timestamp > threshold) {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
timestamp = now;
|
||||
return fn.apply(null, arguments);
|
||||
}
|
||||
if (!timer) {
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
timestamp = Date.now();
|
||||
return fn.apply(null, arguments);
|
||||
}, threshold - (now - timestamp));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate data maxRate
|
||||
* @param {Number} [samplesCount= 10]
|
||||
* @param {Number} [min= 1000]
|
||||
* @returns {Function}
|
||||
*/
|
||||
function speedometer(samplesCount, min) {
|
||||
samplesCount = samplesCount || 10;
|
||||
const bytes = new Array(samplesCount);
|
||||
const timestamps = new Array(samplesCount);
|
||||
let head = 0;
|
||||
let tail = 0;
|
||||
let firstSampleTS;
|
||||
|
||||
min = min !== undefined ? min : 1000;
|
||||
|
||||
return function push(chunkLength) {
|
||||
const now = Date.now();
|
||||
|
||||
const startedAt = timestamps[tail];
|
||||
|
||||
if (!firstSampleTS) {
|
||||
firstSampleTS = now;
|
||||
}
|
||||
|
||||
bytes[head] = chunkLength;
|
||||
timestamps[head] = now;
|
||||
|
||||
let i = tail;
|
||||
let bytesCount = 0;
|
||||
|
||||
while (i !== head) {
|
||||
bytesCount += bytes[i++];
|
||||
i = i % samplesCount;
|
||||
}
|
||||
|
||||
head = (head + 1) % samplesCount;
|
||||
|
||||
if (head === tail) {
|
||||
tail = (tail + 1) % samplesCount;
|
||||
}
|
||||
|
||||
if (now - firstSampleTS < min) {
|
||||
return;
|
||||
}
|
||||
|
||||
const passed = startedAt && now - startedAt;
|
||||
|
||||
return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
|
||||
};
|
||||
}
|
||||
|
||||
const kInternals = Symbol('internals');
|
||||
|
||||
class AxiosTransformStream extends stream__default["default"].Transform{
|
||||
@@ -2193,12 +2141,8 @@ class AxiosTransformStream extends stream__default["default"].Transform{
|
||||
readableHighWaterMark: options.chunkSize
|
||||
});
|
||||
|
||||
const self = this;
|
||||
|
||||
const internals = this[kInternals] = {
|
||||
length: options.length,
|
||||
timeWindow: options.timeWindow,
|
||||
ticksRate: options.ticksRate,
|
||||
chunkSize: options.chunkSize,
|
||||
maxRate: options.maxRate,
|
||||
minChunkSize: options.minChunkSize,
|
||||
@@ -2210,8 +2154,6 @@ class AxiosTransformStream extends stream__default["default"].Transform{
|
||||
onReadCallback: null
|
||||
};
|
||||
|
||||
const _speedometer = speedometer(internals.ticksRate * options.samplesCount, internals.timeWindow);
|
||||
|
||||
this.on('newListener', event => {
|
||||
if (event === 'progress') {
|
||||
if (!internals.isCaptured) {
|
||||
@@ -2219,39 +2161,6 @@ class AxiosTransformStream extends stream__default["default"].Transform{
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let bytesNotified = 0;
|
||||
|
||||
internals.updateProgress = throttle(function throttledHandler() {
|
||||
const totalBytes = internals.length;
|
||||
const bytesTransferred = internals.bytesSeen;
|
||||
const progressBytes = bytesTransferred - bytesNotified;
|
||||
if (!progressBytes || self.destroyed) return;
|
||||
|
||||
const rate = _speedometer(progressBytes);
|
||||
|
||||
bytesNotified = bytesTransferred;
|
||||
|
||||
process.nextTick(() => {
|
||||
self.emit('progress', {
|
||||
loaded: bytesTransferred,
|
||||
total: totalBytes,
|
||||
progress: totalBytes ? (bytesTransferred / totalBytes) : undefined,
|
||||
bytes: progressBytes,
|
||||
rate: rate ? rate : undefined,
|
||||
estimated: rate && totalBytes && bytesTransferred <= totalBytes ?
|
||||
(totalBytes - bytesTransferred) / rate : undefined,
|
||||
lengthComputable: totalBytes != null
|
||||
});
|
||||
});
|
||||
}, internals.ticksRate);
|
||||
|
||||
const onFinish = () => {
|
||||
internals.updateProgress.call(true);
|
||||
};
|
||||
|
||||
this.once('end', onFinish);
|
||||
this.once('error', onFinish);
|
||||
}
|
||||
|
||||
_read(size) {
|
||||
@@ -2265,7 +2174,6 @@ class AxiosTransformStream extends stream__default["default"].Transform{
|
||||
}
|
||||
|
||||
_transform(chunk, encoding, callback) {
|
||||
const self = this;
|
||||
const internals = this[kInternals];
|
||||
const maxRate = internals.maxRate;
|
||||
|
||||
@@ -2277,16 +2185,14 @@ class AxiosTransformStream extends stream__default["default"].Transform{
|
||||
const bytesThreshold = (maxRate / divider);
|
||||
const minChunkSize = internals.minChunkSize !== false ? Math.max(internals.minChunkSize, bytesThreshold * 0.01) : 0;
|
||||
|
||||
function pushChunk(_chunk, _callback) {
|
||||
const pushChunk = (_chunk, _callback) => {
|
||||
const bytes = Buffer.byteLength(_chunk);
|
||||
internals.bytesSeen += bytes;
|
||||
internals.bytes += bytes;
|
||||
|
||||
if (internals.isCaptured) {
|
||||
internals.updateProgress();
|
||||
}
|
||||
internals.isCaptured && this.emit('progress', internals.bytesSeen);
|
||||
|
||||
if (self.push(_chunk)) {
|
||||
if (this.push(_chunk)) {
|
||||
process.nextTick(_callback);
|
||||
} else {
|
||||
internals.onReadCallback = () => {
|
||||
@@ -2294,7 +2200,7 @@ class AxiosTransformStream extends stream__default["default"].Transform{
|
||||
process.nextTick(_callback);
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const transformChunk = (_chunk, _callback) => {
|
||||
const chunkSize = Buffer.byteLength(_chunk);
|
||||
@@ -2351,11 +2257,6 @@ class AxiosTransformStream extends stream__default["default"].Transform{
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setLength(length) {
|
||||
this[kInternals].length = +length;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
const AxiosTransformStream$1 = AxiosTransformStream;
|
||||
@@ -2523,6 +2424,142 @@ const callbackify = (fn, reducer) => {
|
||||
|
||||
const callbackify$1 = callbackify;
|
||||
|
||||
/**
|
||||
* Calculate data maxRate
|
||||
* @param {Number} [samplesCount= 10]
|
||||
* @param {Number} [min= 1000]
|
||||
* @returns {Function}
|
||||
*/
|
||||
function speedometer(samplesCount, min) {
|
||||
samplesCount = samplesCount || 10;
|
||||
const bytes = new Array(samplesCount);
|
||||
const timestamps = new Array(samplesCount);
|
||||
let head = 0;
|
||||
let tail = 0;
|
||||
let firstSampleTS;
|
||||
|
||||
min = min !== undefined ? min : 1000;
|
||||
|
||||
return function push(chunkLength) {
|
||||
const now = Date.now();
|
||||
|
||||
const startedAt = timestamps[tail];
|
||||
|
||||
if (!firstSampleTS) {
|
||||
firstSampleTS = now;
|
||||
}
|
||||
|
||||
bytes[head] = chunkLength;
|
||||
timestamps[head] = now;
|
||||
|
||||
let i = tail;
|
||||
let bytesCount = 0;
|
||||
|
||||
while (i !== head) {
|
||||
bytesCount += bytes[i++];
|
||||
i = i % samplesCount;
|
||||
}
|
||||
|
||||
head = (head + 1) % samplesCount;
|
||||
|
||||
if (head === tail) {
|
||||
tail = (tail + 1) % samplesCount;
|
||||
}
|
||||
|
||||
if (now - firstSampleTS < min) {
|
||||
return;
|
||||
}
|
||||
|
||||
const passed = startedAt && now - startedAt;
|
||||
|
||||
return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Throttle decorator
|
||||
* @param {Function} fn
|
||||
* @param {Number} freq
|
||||
* @return {Function}
|
||||
*/
|
||||
function throttle(fn, freq) {
|
||||
let timestamp = 0;
|
||||
let threshold = 1000 / freq;
|
||||
let lastArgs;
|
||||
let timer;
|
||||
|
||||
const invoke = (args, now = Date.now()) => {
|
||||
timestamp = now;
|
||||
lastArgs = null;
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
fn.apply(null, args);
|
||||
};
|
||||
|
||||
const throttled = (...args) => {
|
||||
const now = Date.now();
|
||||
const passed = now - timestamp;
|
||||
if ( passed >= threshold) {
|
||||
invoke(args, now);
|
||||
} else {
|
||||
lastArgs = args;
|
||||
if (!timer) {
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
invoke(lastArgs);
|
||||
}, threshold - passed);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const flush = () => lastArgs && invoke(lastArgs);
|
||||
|
||||
return [throttled, flush];
|
||||
}
|
||||
|
||||
const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
||||
let bytesNotified = 0;
|
||||
const _speedometer = speedometer(50, 250);
|
||||
|
||||
return throttle(e => {
|
||||
const loaded = e.loaded;
|
||||
const total = e.lengthComputable ? e.total : undefined;
|
||||
const progressBytes = loaded - bytesNotified;
|
||||
const rate = _speedometer(progressBytes);
|
||||
const inRange = loaded <= total;
|
||||
|
||||
bytesNotified = loaded;
|
||||
|
||||
const data = {
|
||||
loaded,
|
||||
total,
|
||||
progress: total ? (loaded / total) : undefined,
|
||||
bytes: progressBytes,
|
||||
rate: rate ? rate : undefined,
|
||||
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
||||
event: e,
|
||||
lengthComputable: total != null,
|
||||
[isDownloadStream ? 'download' : 'upload']: true
|
||||
};
|
||||
|
||||
listener(data);
|
||||
}, freq);
|
||||
};
|
||||
|
||||
const progressEventDecorator = (total, throttled) => {
|
||||
const lengthComputable = total != null;
|
||||
|
||||
return [(loaded) => throttled[0]({
|
||||
lengthComputable,
|
||||
total,
|
||||
loaded
|
||||
}), throttled[1]];
|
||||
};
|
||||
|
||||
const asyncDecorator = (fn) => (...args) => utils$1.asap(() => fn(...args));
|
||||
|
||||
const zlibOptions = {
|
||||
flush: zlib__default["default"].constants.Z_SYNC_FLUSH,
|
||||
finishFlush: zlib__default["default"].constants.Z_SYNC_FLUSH
|
||||
@@ -2543,6 +2580,14 @@ const supportedProtocols = platform.protocols.map(protocol => {
|
||||
return protocol + ':';
|
||||
});
|
||||
|
||||
const flushOnFinish = (stream, [throttled, flush]) => {
|
||||
stream
|
||||
.on('end', flush)
|
||||
.on('error', flush);
|
||||
|
||||
return throttled;
|
||||
};
|
||||
|
||||
/**
|
||||
* If the proxy or config beforeRedirects functions are defined, call them with the options
|
||||
* object.
|
||||
@@ -2776,8 +2821,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
||||
// Only set header if it hasn't been set in config
|
||||
headers.set('User-Agent', 'axios/' + VERSION, false);
|
||||
|
||||
const onDownloadProgress = config.onDownloadProgress;
|
||||
const onUploadProgress = config.onUploadProgress;
|
||||
const {onUploadProgress, onDownloadProgress} = config;
|
||||
const maxRate = config.maxRate;
|
||||
let maxUploadRate = undefined;
|
||||
let maxDownloadRate = undefined;
|
||||
@@ -2848,15 +2892,16 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
||||
}
|
||||
|
||||
data = stream__default["default"].pipeline([data, new AxiosTransformStream$1({
|
||||
length: contentLength,
|
||||
maxRate: utils$1.toFiniteNumber(maxUploadRate)
|
||||
})], utils$1.noop);
|
||||
|
||||
onUploadProgress && data.on('progress', progress => {
|
||||
onUploadProgress(Object.assign(progress, {
|
||||
upload: true
|
||||
}));
|
||||
});
|
||||
onUploadProgress && data.on('progress', flushOnFinish(
|
||||
data,
|
||||
progressEventDecorator(
|
||||
contentLength,
|
||||
progressEventReducer(asyncDecorator(onUploadProgress), false, 3)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
// HTTP basic authentication
|
||||
@@ -2955,17 +3000,18 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
||||
|
||||
const responseLength = +res.headers['content-length'];
|
||||
|
||||
if (onDownloadProgress) {
|
||||
if (onDownloadProgress || maxDownloadRate) {
|
||||
const transformStream = new AxiosTransformStream$1({
|
||||
length: utils$1.toFiniteNumber(responseLength),
|
||||
maxRate: utils$1.toFiniteNumber(maxDownloadRate)
|
||||
});
|
||||
|
||||
onDownloadProgress && transformStream.on('progress', progress => {
|
||||
onDownloadProgress(Object.assign(progress, {
|
||||
download: true
|
||||
}));
|
||||
});
|
||||
onDownloadProgress && transformStream.on('progress', flushOnFinish(
|
||||
transformStream,
|
||||
progressEventDecorator(
|
||||
responseLength,
|
||||
progressEventReducer(asyncDecorator(onDownloadProgress), true, 3)
|
||||
)
|
||||
));
|
||||
|
||||
streams.push(transformStream);
|
||||
}
|
||||
@@ -3178,36 +3224,6 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
||||
});
|
||||
};
|
||||
|
||||
const progressEventReducer = (listener, isDownloadStream, freq = 3) => {
|
||||
let bytesNotified = 0;
|
||||
const _speedometer = speedometer(50, 250);
|
||||
|
||||
return throttle(e => {
|
||||
const loaded = e.loaded;
|
||||
const total = e.lengthComputable ? e.total : undefined;
|
||||
const progressBytes = loaded - bytesNotified;
|
||||
const rate = _speedometer(progressBytes);
|
||||
const inRange = loaded <= total;
|
||||
|
||||
bytesNotified = loaded;
|
||||
|
||||
const data = {
|
||||
loaded,
|
||||
total,
|
||||
progress: total ? (loaded / total) : undefined,
|
||||
bytes: progressBytes,
|
||||
rate: rate ? rate : undefined,
|
||||
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
||||
event: e,
|
||||
lengthComputable: total != null
|
||||
};
|
||||
|
||||
data[isDownloadStream ? 'download' : 'upload'] = true;
|
||||
|
||||
listener(data);
|
||||
}, freq);
|
||||
};
|
||||
|
||||
const isURLSameOrigin = platform.hasStandardBrowserEnv ?
|
||||
|
||||
// Standard browser envs have full support of the APIs needed to test
|
||||
@@ -3467,16 +3483,18 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
const _config = resolveConfig(config);
|
||||
let requestData = _config.data;
|
||||
const requestHeaders = AxiosHeaders$1.from(_config.headers).normalize();
|
||||
let {responseType} = _config;
|
||||
let {responseType, onUploadProgress, onDownloadProgress} = _config;
|
||||
let onCanceled;
|
||||
function done() {
|
||||
if (_config.cancelToken) {
|
||||
_config.cancelToken.unsubscribe(onCanceled);
|
||||
}
|
||||
let uploadThrottled, downloadThrottled;
|
||||
let flushUpload, flushDownload;
|
||||
|
||||
if (_config.signal) {
|
||||
_config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
function done() {
|
||||
flushUpload && flushUpload(); // flush events
|
||||
flushDownload && flushDownload(); // flush events
|
||||
|
||||
_config.cancelToken && _config.cancelToken.unsubscribe(onCanceled);
|
||||
|
||||
_config.signal && _config.signal.removeEventListener('abort', onCanceled);
|
||||
}
|
||||
|
||||
let request = new XMLHttpRequest();
|
||||
@@ -3546,7 +3564,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
return;
|
||||
}
|
||||
|
||||
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, _config, request));
|
||||
reject(new AxiosError('Request aborted', AxiosError.ECONNABORTED, config, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
@@ -3556,7 +3574,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
request.onerror = function handleError() {
|
||||
// Real errors are hidden from us by the browser
|
||||
// onerror should only fire if it's a network error
|
||||
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, _config, request));
|
||||
reject(new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
@@ -3572,7 +3590,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
reject(new AxiosError(
|
||||
timeoutErrorMessage,
|
||||
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
||||
_config,
|
||||
config,
|
||||
request));
|
||||
|
||||
// Clean up request
|
||||
@@ -3600,13 +3618,18 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
|
||||
}
|
||||
|
||||
// Handle progress if needed
|
||||
if (typeof _config.onDownloadProgress === 'function') {
|
||||
request.addEventListener('progress', progressEventReducer(_config.onDownloadProgress, true));
|
||||
if (onDownloadProgress) {
|
||||
([downloadThrottled, flushDownload] = progressEventReducer(onDownloadProgress, true));
|
||||
request.addEventListener('progress', downloadThrottled);
|
||||
}
|
||||
|
||||
// Not all browsers support upload events
|
||||
if (typeof _config.onUploadProgress === 'function' && request.upload) {
|
||||
request.upload.addEventListener('progress', progressEventReducer(_config.onUploadProgress));
|
||||
if (onUploadProgress && request.upload) {
|
||||
([uploadThrottled, flushUpload] = progressEventReducer(onUploadProgress));
|
||||
|
||||
request.upload.addEventListener('progress', uploadThrottled);
|
||||
|
||||
request.upload.addEventListener('loadend', flushUpload);
|
||||
}
|
||||
|
||||
if (_config.cancelToken || _config.signal) {
|
||||
@@ -3712,25 +3735,38 @@ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
||||
const iterator = readBytes(stream, chunkSize, encode);
|
||||
|
||||
let bytes = 0;
|
||||
let done;
|
||||
let _onFinish = (e) => {
|
||||
if (!done) {
|
||||
done = true;
|
||||
onFinish && onFinish(e);
|
||||
}
|
||||
};
|
||||
|
||||
return new ReadableStream({
|
||||
type: 'bytes',
|
||||
|
||||
async pull(controller) {
|
||||
const {done, value} = await iterator.next();
|
||||
try {
|
||||
const {done, value} = await iterator.next();
|
||||
|
||||
if (done) {
|
||||
controller.close();
|
||||
onFinish();
|
||||
return;
|
||||
if (done) {
|
||||
_onFinish();
|
||||
controller.close();
|
||||
return;
|
||||
}
|
||||
|
||||
let len = value.byteLength;
|
||||
if (onProgress) {
|
||||
let loadedBytes = bytes += len;
|
||||
onProgress(loadedBytes);
|
||||
}
|
||||
controller.enqueue(new Uint8Array(value));
|
||||
} catch (err) {
|
||||
_onFinish(err);
|
||||
throw err;
|
||||
}
|
||||
|
||||
let len = value.byteLength;
|
||||
onProgress && onProgress(bytes += len);
|
||||
controller.enqueue(new Uint8Array(value));
|
||||
},
|
||||
cancel(reason) {
|
||||
onFinish(reason);
|
||||
_onFinish(reason);
|
||||
return iterator.return();
|
||||
}
|
||||
}, {
|
||||
@@ -3738,15 +3774,6 @@ const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
|
||||
})
|
||||
};
|
||||
|
||||
const fetchProgressDecorator = (total, fn) => {
|
||||
const lengthComputable = total != null;
|
||||
return (loaded) => setTimeout(() => fn({
|
||||
lengthComputable,
|
||||
total,
|
||||
loaded
|
||||
}));
|
||||
};
|
||||
|
||||
const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
|
||||
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
|
||||
|
||||
@@ -3756,7 +3783,15 @@ const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
||||
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
||||
);
|
||||
|
||||
const supportsRequestStream = isReadableStreamSupported && (() => {
|
||||
const test = (fn, ...args) => {
|
||||
try {
|
||||
return !!fn(...args);
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
};
|
||||
|
||||
const supportsRequestStream = isReadableStreamSupported && test(() => {
|
||||
let duplexAccessed = false;
|
||||
|
||||
const hasContentType = new Request(platform.origin, {
|
||||
@@ -3769,17 +3804,13 @@ const supportsRequestStream = isReadableStreamSupported && (() => {
|
||||
}).headers.has('Content-Type');
|
||||
|
||||
return duplexAccessed && !hasContentType;
|
||||
})();
|
||||
});
|
||||
|
||||
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
||||
|
||||
const supportsResponseStream = isReadableStreamSupported && !!(()=> {
|
||||
try {
|
||||
return utils$1.isReadableStream(new Response('').body);
|
||||
} catch(err) {
|
||||
// return undefined
|
||||
}
|
||||
})();
|
||||
const supportsResponseStream = isReadableStreamSupported &&
|
||||
test(() => utils$1.isReadableStream(new Response('').body));
|
||||
|
||||
|
||||
const resolvers = {
|
||||
stream: supportsResponseStream && ((res) => res.body)
|
||||
@@ -3807,7 +3838,7 @@ const getBodyLength = async (body) => {
|
||||
return (await new Request(body).arrayBuffer()).byteLength;
|
||||
}
|
||||
|
||||
if(utils$1.isArrayBufferView(body)) {
|
||||
if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
|
||||
return body.byteLength;
|
||||
}
|
||||
|
||||
@@ -3877,15 +3908,17 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
||||
}
|
||||
|
||||
if (_request.body) {
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(
|
||||
const [onProgress, flush] = progressEventDecorator(
|
||||
requestContentLength,
|
||||
progressEventReducer(onUploadProgress)
|
||||
), null, encodeText);
|
||||
progressEventReducer(asyncDecorator(onUploadProgress))
|
||||
);
|
||||
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
|
||||
}
|
||||
}
|
||||
|
||||
if (!utils$1.isString(withCredentials)) {
|
||||
withCredentials = withCredentials ? 'cors' : 'omit';
|
||||
withCredentials = withCredentials ? 'include' : 'omit';
|
||||
}
|
||||
|
||||
request = new Request(url, {
|
||||
@@ -3895,7 +3928,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
||||
headers: headers.normalize().toJSON(),
|
||||
body: data,
|
||||
duplex: "half",
|
||||
withCredentials
|
||||
credentials: withCredentials
|
||||
});
|
||||
|
||||
let response = await fetch(request);
|
||||
@@ -3911,11 +3944,16 @@ const fetchAdapter = isFetchSupported && (async (config) => {
|
||||
|
||||
const responseContentLength = utils$1.toFiniteNumber(response.headers.get('content-length'));
|
||||
|
||||
const [onProgress, flush] = onDownloadProgress && progressEventDecorator(
|
||||
responseContentLength,
|
||||
progressEventReducer(asyncDecorator(onDownloadProgress), true)
|
||||
) || [];
|
||||
|
||||
response = new Response(
|
||||
trackStream(response.body, DEFAULT_CHUNK_SIZE, onDownloadProgress && fetchProgressDecorator(
|
||||
responseContentLength,
|
||||
progressEventReducer(onDownloadProgress, true)
|
||||
), isStreamResponse && onFinish, encodeText),
|
||||
trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
|
||||
flush && flush();
|
||||
isStreamResponse && onFinish();
|
||||
}, encodeText),
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -1 +1 @@
|
||||
export const VERSION = "1.7.2";
|
||||
export const VERSION = "1.7.3";
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "axios",
|
||||
"version": "1.7.2",
|
||||
"version": "1.7.3",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "axios",
|
||||
"version": "1.7.2",
|
||||
"version": "1.7.3",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "axios",
|
||||
"version": "1.7.2",
|
||||
"version": "1.7.3",
|
||||
"description": "Promise based HTTP client for the browser and node.js",
|
||||
"main": "index.js",
|
||||
"exports": {
|
||||
|
||||
Reference in New Issue
Block a user