2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-20 20:00:40 +03:00

chore(release): v1.7.3 (#6521)

Co-authored-by: DigitalBrainJS <12586868+DigitalBrainJS@users.noreply.github.com>
This commit is contained in:
github-actions[bot]
2024-08-01 19:15:27 +03:00
committed by GitHub
parent e3c76fc9bd
commit c6cce43cd9
17 changed files with 785 additions and 490 deletions
+156 -80
View File
@@ -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 = {};
+1 -1
View File
File diff suppressed because one or more lines are too long