优化首页的下拉刷新、数据排序、绑定后刷新
This commit is contained in:
133
node_modules/axios/lib/adapters/adapters.js
generated
vendored
133
node_modules/axios/lib/adapters/adapters.js
generated
vendored
@ -1,79 +1,126 @@
|
||||
import utils from '../utils.js';
|
||||
import httpAdapter from './http.js';
|
||||
import xhrAdapter from './xhr.js';
|
||||
import fetchAdapter from './fetch.js';
|
||||
import * as fetchAdapter from './fetch.js';
|
||||
import AxiosError from "../core/AxiosError.js";
|
||||
|
||||
/**
|
||||
* Known adapters mapping.
|
||||
* Provides environment-specific adapters for Axios:
|
||||
* - `http` for Node.js
|
||||
* - `xhr` for browsers
|
||||
* - `fetch` for fetch API-based requests
|
||||
*
|
||||
* @type {Object<string, Function|Object>}
|
||||
*/
|
||||
const knownAdapters = {
|
||||
http: httpAdapter,
|
||||
xhr: xhrAdapter,
|
||||
fetch: fetchAdapter
|
||||
}
|
||||
fetch: {
|
||||
get: fetchAdapter.getFetch,
|
||||
}
|
||||
};
|
||||
|
||||
// Assign adapter names for easier debugging and identification
|
||||
utils.forEach(knownAdapters, (fn, value) => {
|
||||
if (fn) {
|
||||
try {
|
||||
Object.defineProperty(fn, 'name', {value});
|
||||
Object.defineProperty(fn, 'name', { value });
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line no-empty
|
||||
}
|
||||
Object.defineProperty(fn, 'adapterName', {value});
|
||||
Object.defineProperty(fn, 'adapterName', { value });
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Render a rejection reason string for unknown or unsupported adapters
|
||||
*
|
||||
* @param {string} reason
|
||||
* @returns {string}
|
||||
*/
|
||||
const renderReason = (reason) => `- ${reason}`;
|
||||
|
||||
/**
|
||||
* Check if the adapter is resolved (function, null, or false)
|
||||
*
|
||||
* @param {Function|null|false} adapter
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
|
||||
|
||||
export default {
|
||||
getAdapter: (adapters) => {
|
||||
adapters = utils.isArray(adapters) ? adapters : [adapters];
|
||||
/**
|
||||
* Get the first suitable adapter from the provided list.
|
||||
* Tries each adapter in order until a supported one is found.
|
||||
* Throws an AxiosError if no adapter is suitable.
|
||||
*
|
||||
* @param {Array<string|Function>|string|Function} adapters - Adapter(s) by name or function.
|
||||
* @param {Object} config - Axios request configuration
|
||||
* @throws {AxiosError} If no suitable adapter is available
|
||||
* @returns {Function} The resolved adapter function
|
||||
*/
|
||||
function getAdapter(adapters, config) {
|
||||
adapters = utils.isArray(adapters) ? adapters : [adapters];
|
||||
|
||||
const {length} = adapters;
|
||||
let nameOrAdapter;
|
||||
let adapter;
|
||||
const { length } = adapters;
|
||||
let nameOrAdapter;
|
||||
let adapter;
|
||||
|
||||
const rejectedReasons = {};
|
||||
const rejectedReasons = {};
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
nameOrAdapter = adapters[i];
|
||||
let id;
|
||||
for (let i = 0; i < length; i++) {
|
||||
nameOrAdapter = adapters[i];
|
||||
let id;
|
||||
|
||||
adapter = nameOrAdapter;
|
||||
adapter = nameOrAdapter;
|
||||
|
||||
if (!isResolvedHandle(nameOrAdapter)) {
|
||||
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
||||
if (!isResolvedHandle(nameOrAdapter)) {
|
||||
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
||||
|
||||
if (adapter === undefined) {
|
||||
throw new AxiosError(`Unknown adapter '${id}'`);
|
||||
}
|
||||
if (adapter === undefined) {
|
||||
throw new AxiosError(`Unknown adapter '${id}'`);
|
||||
}
|
||||
|
||||
if (adapter) {
|
||||
break;
|
||||
}
|
||||
|
||||
rejectedReasons[id || '#' + i] = adapter;
|
||||
}
|
||||
|
||||
if (!adapter) {
|
||||
if (adapter && (utils.isFunction(adapter) || (adapter = adapter.get(config)))) {
|
||||
break;
|
||||
}
|
||||
|
||||
const reasons = Object.entries(rejectedReasons)
|
||||
.map(([id, state]) => `adapter ${id} ` +
|
||||
(state === false ? 'is not supported by the environment' : 'is not available in the build')
|
||||
);
|
||||
rejectedReasons[id || '#' + i] = adapter;
|
||||
}
|
||||
|
||||
let s = length ?
|
||||
(reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
|
||||
'as no adapter specified';
|
||||
|
||||
throw new AxiosError(
|
||||
`There is no suitable adapter to dispatch the request ` + s,
|
||||
'ERR_NOT_SUPPORT'
|
||||
if (!adapter) {
|
||||
const reasons = Object.entries(rejectedReasons)
|
||||
.map(([id, state]) => `adapter ${id} ` +
|
||||
(state === false ? 'is not supported by the environment' : 'is not available in the build')
|
||||
);
|
||||
}
|
||||
|
||||
return adapter;
|
||||
},
|
||||
adapters: knownAdapters
|
||||
let s = length ?
|
||||
(reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
|
||||
'as no adapter specified';
|
||||
|
||||
throw new AxiosError(
|
||||
`There is no suitable adapter to dispatch the request ` + s,
|
||||
'ERR_NOT_SUPPORT'
|
||||
);
|
||||
}
|
||||
|
||||
return adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exports Axios adapters and utility to resolve an adapter
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* Resolve an adapter from a list of adapter names or functions.
|
||||
* @type {Function}
|
||||
*/
|
||||
getAdapter,
|
||||
|
||||
/**
|
||||
* Exposes all known adapters
|
||||
* @type {Object<string, Function|Object>}
|
||||
*/
|
||||
adapters: knownAdapters
|
||||
};
|
||||
|
||||
419
node_modules/axios/lib/adapters/fetch.js
generated
vendored
419
node_modules/axios/lib/adapters/fetch.js
generated
vendored
@ -8,14 +8,18 @@ import {progressEventReducer, progressEventDecorator, asyncDecorator} from "../h
|
||||
import resolveConfig from "../helpers/resolveConfig.js";
|
||||
import settle from "../core/settle.js";
|
||||
|
||||
const isFetchSupported = typeof fetch === 'function' && typeof Request === 'function' && typeof Response === 'function';
|
||||
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream === 'function';
|
||||
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
||||
|
||||
const {isFunction} = utils;
|
||||
|
||||
const globalFetchAPI = (({Request, Response}) => ({
|
||||
Request, Response
|
||||
}))(utils.global);
|
||||
|
||||
const {
|
||||
ReadableStream, TextEncoder
|
||||
} = utils.global;
|
||||
|
||||
// used only inside the fetch adapter
|
||||
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
||||
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
||||
async (str) => new Uint8Array(await new Response(str).arrayBuffer())
|
||||
);
|
||||
|
||||
const test = (fn, ...args) => {
|
||||
try {
|
||||
@ -25,205 +29,260 @@ const test = (fn, ...args) => {
|
||||
}
|
||||
}
|
||||
|
||||
const supportsRequestStream = isReadableStreamSupported && test(() => {
|
||||
let duplexAccessed = false;
|
||||
const factory = (env) => {
|
||||
env = utils.merge.call({
|
||||
skipUndefined: true
|
||||
}, globalFetchAPI, env);
|
||||
|
||||
const hasContentType = new Request(platform.origin, {
|
||||
body: new ReadableStream(),
|
||||
method: 'POST',
|
||||
get duplex() {
|
||||
duplexAccessed = true;
|
||||
return 'half';
|
||||
},
|
||||
}).headers.has('Content-Type');
|
||||
const {fetch: envFetch, Request, Response} = env;
|
||||
const isFetchSupported = envFetch ? isFunction(envFetch) : typeof fetch === 'function';
|
||||
const isRequestSupported = isFunction(Request);
|
||||
const isResponseSupported = isFunction(Response);
|
||||
|
||||
return duplexAccessed && !hasContentType;
|
||||
});
|
||||
if (!isFetchSupported) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
||||
const isReadableStreamSupported = isFetchSupported && isFunction(ReadableStream);
|
||||
|
||||
const supportsResponseStream = isReadableStreamSupported &&
|
||||
test(() => utils.isReadableStream(new Response('').body));
|
||||
const encodeText = isFetchSupported && (typeof TextEncoder === 'function' ?
|
||||
((encoder) => (str) => encoder.encode(str))(new TextEncoder()) :
|
||||
async (str) => new Uint8Array(await new Request(str).arrayBuffer())
|
||||
);
|
||||
|
||||
const supportsRequestStream = isRequestSupported && isReadableStreamSupported && test(() => {
|
||||
let duplexAccessed = false;
|
||||
|
||||
const resolvers = {
|
||||
stream: supportsResponseStream && ((res) => res.body)
|
||||
};
|
||||
const hasContentType = new Request(platform.origin, {
|
||||
body: new ReadableStream(),
|
||||
method: 'POST',
|
||||
get duplex() {
|
||||
duplexAccessed = true;
|
||||
return 'half';
|
||||
},
|
||||
}).headers.has('Content-Type');
|
||||
|
||||
return duplexAccessed && !hasContentType;
|
||||
});
|
||||
|
||||
const supportsResponseStream = isResponseSupported && isReadableStreamSupported &&
|
||||
test(() => utils.isReadableStream(new Response('').body));
|
||||
|
||||
const resolvers = {
|
||||
stream: supportsResponseStream && ((res) => res.body)
|
||||
};
|
||||
|
||||
isFetchSupported && ((() => {
|
||||
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
||||
!resolvers[type] && (resolvers[type] = (res, config) => {
|
||||
let method = res && res[type];
|
||||
|
||||
if (method) {
|
||||
return method.call(res);
|
||||
}
|
||||
|
||||
isFetchSupported && (((res) => {
|
||||
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
||||
!resolvers[type] && (resolvers[type] = utils.isFunction(res[type]) ? (res) => res[type]() :
|
||||
(_, config) => {
|
||||
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
||||
})
|
||||
});
|
||||
})(new Response));
|
||||
|
||||
const getBodyLength = async (body) => {
|
||||
if (body == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(utils.isBlob(body)) {
|
||||
return body.size;
|
||||
}
|
||||
|
||||
if(utils.isSpecCompliantForm(body)) {
|
||||
const _request = new Request(platform.origin, {
|
||||
method: 'POST',
|
||||
body,
|
||||
});
|
||||
return (await _request.arrayBuffer()).byteLength;
|
||||
}
|
||||
})());
|
||||
|
||||
if(utils.isArrayBufferView(body) || utils.isArrayBuffer(body)) {
|
||||
return body.byteLength;
|
||||
}
|
||||
const getBodyLength = async (body) => {
|
||||
if (body == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(utils.isURLSearchParams(body)) {
|
||||
body = body + '';
|
||||
}
|
||||
if (utils.isBlob(body)) {
|
||||
return body.size;
|
||||
}
|
||||
|
||||
if(utils.isString(body)) {
|
||||
return (await encodeText(body)).byteLength;
|
||||
}
|
||||
}
|
||||
|
||||
const resolveBodyLength = async (headers, body) => {
|
||||
const length = utils.toFiniteNumber(headers.getContentLength());
|
||||
|
||||
return length == null ? getBodyLength(body) : length;
|
||||
}
|
||||
|
||||
export default isFetchSupported && (async (config) => {
|
||||
let {
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
signal,
|
||||
cancelToken,
|
||||
timeout,
|
||||
onDownloadProgress,
|
||||
onUploadProgress,
|
||||
responseType,
|
||||
headers,
|
||||
withCredentials = 'same-origin',
|
||||
fetchOptions
|
||||
} = resolveConfig(config);
|
||||
|
||||
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
||||
|
||||
let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
||||
|
||||
let request;
|
||||
|
||||
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
||||
composedSignal.unsubscribe();
|
||||
});
|
||||
|
||||
let requestContentLength;
|
||||
|
||||
try {
|
||||
if (
|
||||
onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
|
||||
(requestContentLength = await resolveBodyLength(headers, data)) !== 0
|
||||
) {
|
||||
let _request = new Request(url, {
|
||||
if (utils.isSpecCompliantForm(body)) {
|
||||
const _request = new Request(platform.origin, {
|
||||
method: 'POST',
|
||||
body: data,
|
||||
duplex: "half"
|
||||
body,
|
||||
});
|
||||
|
||||
let contentTypeHeader;
|
||||
|
||||
if (utils.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
|
||||
headers.setContentType(contentTypeHeader)
|
||||
}
|
||||
|
||||
if (_request.body) {
|
||||
const [onProgress, flush] = progressEventDecorator(
|
||||
requestContentLength,
|
||||
progressEventReducer(asyncDecorator(onUploadProgress))
|
||||
);
|
||||
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
||||
}
|
||||
return (await _request.arrayBuffer()).byteLength;
|
||||
}
|
||||
|
||||
if (!utils.isString(withCredentials)) {
|
||||
withCredentials = withCredentials ? 'include' : 'omit';
|
||||
if (utils.isArrayBufferView(body) || utils.isArrayBuffer(body)) {
|
||||
return body.byteLength;
|
||||
}
|
||||
|
||||
// Cloudflare Workers throws when credentials are defined
|
||||
// see https://github.com/cloudflare/workerd/issues/902
|
||||
const isCredentialsSupported = "credentials" in Request.prototype;
|
||||
request = new Request(url, {
|
||||
...fetchOptions,
|
||||
signal: composedSignal,
|
||||
method: method.toUpperCase(),
|
||||
headers: headers.normalize().toJSON(),
|
||||
body: data,
|
||||
duplex: "half",
|
||||
credentials: isCredentialsSupported ? withCredentials : undefined
|
||||
if (utils.isURLSearchParams(body)) {
|
||||
body = body + '';
|
||||
}
|
||||
|
||||
if (utils.isString(body)) {
|
||||
return (await encodeText(body)).byteLength;
|
||||
}
|
||||
}
|
||||
|
||||
const resolveBodyLength = async (headers, body) => {
|
||||
const length = utils.toFiniteNumber(headers.getContentLength());
|
||||
|
||||
return length == null ? getBodyLength(body) : length;
|
||||
}
|
||||
|
||||
return async (config) => {
|
||||
let {
|
||||
url,
|
||||
method,
|
||||
data,
|
||||
signal,
|
||||
cancelToken,
|
||||
timeout,
|
||||
onDownloadProgress,
|
||||
onUploadProgress,
|
||||
responseType,
|
||||
headers,
|
||||
withCredentials = 'same-origin',
|
||||
fetchOptions
|
||||
} = resolveConfig(config);
|
||||
|
||||
let _fetch = envFetch || fetch;
|
||||
|
||||
responseType = responseType ? (responseType + '').toLowerCase() : 'text';
|
||||
|
||||
let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
||||
|
||||
let request = null;
|
||||
|
||||
const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
|
||||
composedSignal.unsubscribe();
|
||||
});
|
||||
|
||||
let response = await fetch(request);
|
||||
let requestContentLength;
|
||||
|
||||
const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
||||
try {
|
||||
if (
|
||||
onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
|
||||
(requestContentLength = await resolveBodyLength(headers, data)) !== 0
|
||||
) {
|
||||
let _request = new Request(url, {
|
||||
method: 'POST',
|
||||
body: data,
|
||||
duplex: "half"
|
||||
});
|
||||
|
||||
if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
|
||||
const options = {};
|
||||
let contentTypeHeader;
|
||||
|
||||
['status', 'statusText', 'headers'].forEach(prop => {
|
||||
options[prop] = response[prop];
|
||||
});
|
||||
|
||||
const responseContentLength = utils.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, onProgress, () => {
|
||||
flush && flush();
|
||||
unsubscribe && unsubscribe();
|
||||
}),
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
responseType = responseType || 'text';
|
||||
|
||||
let responseData = await resolvers[utils.findKey(resolvers, responseType) || 'text'](response, config);
|
||||
|
||||
!isStreamResponse && unsubscribe && unsubscribe();
|
||||
|
||||
return await new Promise((resolve, reject) => {
|
||||
settle(resolve, reject, {
|
||||
data: responseData,
|
||||
headers: AxiosHeaders.from(response.headers),
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
config,
|
||||
request
|
||||
})
|
||||
})
|
||||
} catch (err) {
|
||||
unsubscribe && unsubscribe();
|
||||
|
||||
if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
|
||||
throw Object.assign(
|
||||
new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
|
||||
{
|
||||
cause: err.cause || err
|
||||
if (utils.isFormData(data) && (contentTypeHeader = _request.headers.get('content-type'))) {
|
||||
headers.setContentType(contentTypeHeader)
|
||||
}
|
||||
)
|
||||
|
||||
if (_request.body) {
|
||||
const [onProgress, flush] = progressEventDecorator(
|
||||
requestContentLength,
|
||||
progressEventReducer(asyncDecorator(onUploadProgress))
|
||||
);
|
||||
|
||||
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
|
||||
}
|
||||
}
|
||||
|
||||
if (!utils.isString(withCredentials)) {
|
||||
withCredentials = withCredentials ? 'include' : 'omit';
|
||||
}
|
||||
|
||||
// Cloudflare Workers throws when credentials are defined
|
||||
// see https://github.com/cloudflare/workerd/issues/902
|
||||
const isCredentialsSupported = isRequestSupported && "credentials" in Request.prototype;
|
||||
|
||||
const resolvedOptions = {
|
||||
...fetchOptions,
|
||||
signal: composedSignal,
|
||||
method: method.toUpperCase(),
|
||||
headers: headers.normalize().toJSON(),
|
||||
body: data,
|
||||
duplex: "half",
|
||||
credentials: isCredentialsSupported ? withCredentials : undefined
|
||||
};
|
||||
|
||||
request = isRequestSupported && new Request(url, resolvedOptions);
|
||||
|
||||
let response = await (isRequestSupported ? _fetch(request, fetchOptions) : _fetch(url, resolvedOptions));
|
||||
|
||||
const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
|
||||
|
||||
if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
|
||||
const options = {};
|
||||
|
||||
['status', 'statusText', 'headers'].forEach(prop => {
|
||||
options[prop] = response[prop];
|
||||
});
|
||||
|
||||
const responseContentLength = utils.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, onProgress, () => {
|
||||
flush && flush();
|
||||
unsubscribe && unsubscribe();
|
||||
}),
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
responseType = responseType || 'text';
|
||||
|
||||
let responseData = await resolvers[utils.findKey(resolvers, responseType) || 'text'](response, config);
|
||||
|
||||
!isStreamResponse && unsubscribe && unsubscribe();
|
||||
|
||||
return await new Promise((resolve, reject) => {
|
||||
settle(resolve, reject, {
|
||||
data: responseData,
|
||||
headers: AxiosHeaders.from(response.headers),
|
||||
status: response.status,
|
||||
statusText: response.statusText,
|
||||
config,
|
||||
request
|
||||
})
|
||||
})
|
||||
} catch (err) {
|
||||
unsubscribe && unsubscribe();
|
||||
|
||||
if (err && err.name === 'TypeError' && /Load failed|fetch/i.test(err.message)) {
|
||||
throw Object.assign(
|
||||
new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
|
||||
{
|
||||
cause: err.cause || err
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
throw AxiosError.from(err, err && err.code, config, request);
|
||||
}
|
||||
|
||||
throw AxiosError.from(err, err && err.code, config, request);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const seedCache = new Map();
|
||||
|
||||
export const getFetch = (config) => {
|
||||
let env = (config && config.env) || {};
|
||||
const {fetch, Request, Response} = env;
|
||||
const seeds = [
|
||||
Request, Response, fetch
|
||||
];
|
||||
|
||||
let len = seeds.length, i = len,
|
||||
seed, target, map = seedCache;
|
||||
|
||||
while (i--) {
|
||||
seed = seeds[i];
|
||||
target = map.get(seed);
|
||||
|
||||
target === undefined && map.set(seed, target = (i ? new Map() : factory(env)))
|
||||
|
||||
map = target;
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
||||
|
||||
const adapter = getFetch();
|
||||
|
||||
export default adapter;
|
||||
|
||||
290
node_modules/axios/lib/adapters/http.js
generated
vendored
290
node_modules/axios/lib/adapters/http.js
generated
vendored
@ -1,5 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
import utils from './../utils.js';
|
||||
import settle from './../core/settle.js';
|
||||
import buildFullPath from '../core/buildFullPath.js';
|
||||
@ -7,6 +5,7 @@ import buildURL from './../helpers/buildURL.js';
|
||||
import proxyFromEnv from 'proxy-from-env';
|
||||
import http from 'http';
|
||||
import https from 'https';
|
||||
import http2 from 'http2';
|
||||
import util from 'util';
|
||||
import followRedirects from 'follow-redirects';
|
||||
import zlib from 'zlib';
|
||||
@ -25,6 +24,7 @@ import readBlob from "../helpers/readBlob.js";
|
||||
import ZlibHeaderTransformStream from '../helpers/ZlibHeaderTransformStream.js';
|
||||
import callbackify from "../helpers/callbackify.js";
|
||||
import {progressEventReducer, progressEventDecorator, asyncDecorator} from "../helpers/progressEventReducer.js";
|
||||
import estimateDataURLDecodedBytes from '../helpers/estimateDataURLDecodedBytes.js';
|
||||
|
||||
const zlibOptions = {
|
||||
flush: zlib.constants.Z_SYNC_FLUSH,
|
||||
@ -46,6 +46,7 @@ const supportedProtocols = platform.protocols.map(protocol => {
|
||||
return protocol + ':';
|
||||
});
|
||||
|
||||
|
||||
const flushOnFinish = (stream, [throttled, flush]) => {
|
||||
stream
|
||||
.on('end', flush)
|
||||
@ -54,6 +55,102 @@ const flushOnFinish = (stream, [throttled, flush]) => {
|
||||
return throttled;
|
||||
}
|
||||
|
||||
class Http2Sessions {
|
||||
constructor() {
|
||||
this.sessions = Object.create(null);
|
||||
}
|
||||
|
||||
getSession(authority, options) {
|
||||
options = Object.assign({
|
||||
sessionTimeout: 1000
|
||||
}, options);
|
||||
|
||||
let authoritySessions = this.sessions[authority];
|
||||
|
||||
if (authoritySessions) {
|
||||
let len = authoritySessions.length;
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
const [sessionHandle, sessionOptions] = authoritySessions[i];
|
||||
if (!sessionHandle.destroyed && !sessionHandle.closed && util.isDeepStrictEqual(sessionOptions, options)) {
|
||||
return sessionHandle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const session = http2.connect(authority, options);
|
||||
|
||||
let removed;
|
||||
|
||||
const removeSession = () => {
|
||||
if (removed) {
|
||||
return;
|
||||
}
|
||||
|
||||
removed = true;
|
||||
|
||||
let entries = authoritySessions, len = entries.length, i = len;
|
||||
|
||||
while (i--) {
|
||||
if (entries[i][0] === session) {
|
||||
if (len === 1) {
|
||||
delete this.sessions[authority];
|
||||
} else {
|
||||
entries.splice(i, 1);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const originalRequestFn = session.request;
|
||||
|
||||
const {sessionTimeout} = options;
|
||||
|
||||
if(sessionTimeout != null) {
|
||||
|
||||
let timer;
|
||||
let streamsCount = 0;
|
||||
|
||||
session.request = function () {
|
||||
const stream = originalRequestFn.apply(this, arguments);
|
||||
|
||||
streamsCount++;
|
||||
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
|
||||
stream.once('close', () => {
|
||||
if (!--streamsCount) {
|
||||
timer = setTimeout(() => {
|
||||
timer = null;
|
||||
removeSession();
|
||||
}, sessionTimeout);
|
||||
}
|
||||
});
|
||||
|
||||
return stream;
|
||||
}
|
||||
}
|
||||
|
||||
session.once('close', removeSession);
|
||||
|
||||
let entry = [
|
||||
session,
|
||||
options
|
||||
];
|
||||
|
||||
authoritySessions ? authoritySessions.push(entry) : authoritySessions = this.sessions[authority] = [entry];
|
||||
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
||||
const http2Sessions = new Http2Sessions();
|
||||
|
||||
|
||||
/**
|
||||
* If the proxy or config beforeRedirects functions are defined, call them with the options
|
||||
* object.
|
||||
@ -165,16 +262,75 @@ const resolveFamily = ({address, family}) => {
|
||||
|
||||
const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(address) ? address : {address, family});
|
||||
|
||||
const http2Transport = {
|
||||
request(options, cb) {
|
||||
const authority = options.protocol + '//' + options.hostname + ':' + (options.port || 80);
|
||||
|
||||
const {http2Options, headers} = options;
|
||||
|
||||
const session = http2Sessions.getSession(authority, http2Options);
|
||||
|
||||
const {
|
||||
HTTP2_HEADER_SCHEME,
|
||||
HTTP2_HEADER_METHOD,
|
||||
HTTP2_HEADER_PATH,
|
||||
HTTP2_HEADER_STATUS
|
||||
} = http2.constants;
|
||||
|
||||
const http2Headers = {
|
||||
[HTTP2_HEADER_SCHEME]: options.protocol.replace(':', ''),
|
||||
[HTTP2_HEADER_METHOD]: options.method,
|
||||
[HTTP2_HEADER_PATH]: options.path,
|
||||
}
|
||||
|
||||
utils.forEach(headers, (header, name) => {
|
||||
name.charAt(0) !== ':' && (http2Headers[name] = header);
|
||||
});
|
||||
|
||||
const req = session.request(http2Headers);
|
||||
|
||||
req.once('response', (responseHeaders) => {
|
||||
const response = req; //duplex
|
||||
|
||||
responseHeaders = Object.assign({}, responseHeaders);
|
||||
|
||||
const status = responseHeaders[HTTP2_HEADER_STATUS];
|
||||
|
||||
delete responseHeaders[HTTP2_HEADER_STATUS];
|
||||
|
||||
response.headers = responseHeaders;
|
||||
|
||||
response.statusCode = +status;
|
||||
|
||||
cb(response);
|
||||
})
|
||||
|
||||
return req;
|
||||
}
|
||||
}
|
||||
|
||||
/*eslint consistent-return:0*/
|
||||
export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
|
||||
let {data, lookup, family} = config;
|
||||
let {data, lookup, family, httpVersion = 1, http2Options} = config;
|
||||
const {responseType, responseEncoding} = config;
|
||||
const method = config.method.toUpperCase();
|
||||
let isDone;
|
||||
let rejected = false;
|
||||
let req;
|
||||
|
||||
httpVersion = +httpVersion;
|
||||
|
||||
if (Number.isNaN(httpVersion)) {
|
||||
throw TypeError(`Invalid protocol version: '${config.httpVersion}' is not a number`);
|
||||
}
|
||||
|
||||
if (httpVersion !== 1 && httpVersion !== 2) {
|
||||
throw TypeError(`Unsupported protocol version '${httpVersion}'`);
|
||||
}
|
||||
|
||||
const isHttp2 = httpVersion === 2;
|
||||
|
||||
if (lookup) {
|
||||
const _lookup = callbackify(lookup, (value) => utils.isArray(value) ? value : [value]);
|
||||
// hotfix to support opt.all option which is required for node 20.x
|
||||
@ -191,8 +347,17 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
}
|
||||
}
|
||||
|
||||
// temporary internal emitter until the AxiosRequest class will be implemented
|
||||
const emitter = new EventEmitter();
|
||||
const abortEmitter = new EventEmitter();
|
||||
|
||||
function abort(reason) {
|
||||
try {
|
||||
abortEmitter.emit('abort', !reason || reason.type ? new CanceledError(null, config, req) : reason);
|
||||
} catch(err) {
|
||||
console.warn('emit error', err);
|
||||
}
|
||||
}
|
||||
|
||||
abortEmitter.once('abort', reject);
|
||||
|
||||
const onFinished = () => {
|
||||
if (config.cancelToken) {
|
||||
@ -203,23 +368,9 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
config.signal.removeEventListener('abort', abort);
|
||||
}
|
||||
|
||||
emitter.removeAllListeners();
|
||||
abortEmitter.removeAllListeners();
|
||||
}
|
||||
|
||||
onDone((value, isRejected) => {
|
||||
isDone = true;
|
||||
if (isRejected) {
|
||||
rejected = true;
|
||||
onFinished();
|
||||
}
|
||||
});
|
||||
|
||||
function abort(reason) {
|
||||
emitter.emit('abort', !reason || reason.type ? new CanceledError(null, config, req) : reason);
|
||||
}
|
||||
|
||||
emitter.once('abort', reject);
|
||||
|
||||
if (config.cancelToken || config.signal) {
|
||||
config.cancelToken && config.cancelToken.subscribe(abort);
|
||||
if (config.signal) {
|
||||
@ -227,12 +378,52 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
}
|
||||
}
|
||||
|
||||
onDone((response, isRejected) => {
|
||||
isDone = true;
|
||||
|
||||
if (isRejected) {
|
||||
rejected = true;
|
||||
onFinished();
|
||||
return;
|
||||
}
|
||||
|
||||
const {data} = response;
|
||||
|
||||
if (data instanceof stream.Readable || data instanceof stream.Duplex) {
|
||||
const offListeners = stream.finished(data, () => {
|
||||
offListeners();
|
||||
onFinished();
|
||||
});
|
||||
} else {
|
||||
onFinished();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Parse url
|
||||
const fullPath = buildFullPath(config.baseURL, config.url, config.allowAbsoluteUrls);
|
||||
const parsed = new URL(fullPath, platform.hasBrowserEnv ? platform.origin : undefined);
|
||||
const protocol = parsed.protocol || supportedProtocols[0];
|
||||
|
||||
if (protocol === 'data:') {
|
||||
// Apply the same semantics as HTTP: only enforce if a finite, non-negative cap is set.
|
||||
if (config.maxContentLength > -1) {
|
||||
// Use the exact string passed to fromDataURI (config.url); fall back to fullPath if needed.
|
||||
const dataUrl = String(config.url || fullPath || '');
|
||||
const estimated = estimateDataURLDecodedBytes(dataUrl);
|
||||
|
||||
if (estimated > config.maxContentLength) {
|
||||
return reject(new AxiosError(
|
||||
'maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
||||
AxiosError.ERR_BAD_RESPONSE,
|
||||
config
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
let convertedData;
|
||||
|
||||
if (method !== 'GET') {
|
||||
@ -418,7 +609,8 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
protocol,
|
||||
family,
|
||||
beforeRedirect: dispatchBeforeRedirect,
|
||||
beforeRedirects: {}
|
||||
beforeRedirects: {},
|
||||
http2Options
|
||||
};
|
||||
|
||||
// cacheable-lookup integration hotfix
|
||||
@ -435,18 +627,23 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
let transport;
|
||||
const isHttpsRequest = isHttps.test(options.protocol);
|
||||
options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
||||
if (config.transport) {
|
||||
transport = config.transport;
|
||||
} else if (config.maxRedirects === 0) {
|
||||
transport = isHttpsRequest ? https : http;
|
||||
|
||||
if (isHttp2) {
|
||||
transport = http2Transport;
|
||||
} else {
|
||||
if (config.maxRedirects) {
|
||||
options.maxRedirects = config.maxRedirects;
|
||||
if (config.transport) {
|
||||
transport = config.transport;
|
||||
} else if (config.maxRedirects === 0) {
|
||||
transport = isHttpsRequest ? https : http;
|
||||
} else {
|
||||
if (config.maxRedirects) {
|
||||
options.maxRedirects = config.maxRedirects;
|
||||
}
|
||||
if (config.beforeRedirect) {
|
||||
options.beforeRedirects.config = config.beforeRedirect;
|
||||
}
|
||||
transport = isHttpsRequest ? httpsFollow : httpFollow;
|
||||
}
|
||||
if (config.beforeRedirect) {
|
||||
options.beforeRedirects.config = config.beforeRedirect;
|
||||
}
|
||||
transport = isHttpsRequest ? httpsFollow : httpFollow;
|
||||
}
|
||||
|
||||
if (config.maxBodyLength > -1) {
|
||||
@ -466,7 +663,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
|
||||
const streams = [res];
|
||||
|
||||
const responseLength = +res.headers['content-length'];
|
||||
const responseLength = utils.toFiniteNumber(res.headers['content-length']);
|
||||
|
||||
if (onDownloadProgress || maxDownloadRate) {
|
||||
const transformStream = new AxiosTransformStream({
|
||||
@ -529,10 +726,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
|
||||
responseStream = streams.length > 1 ? stream.pipeline(streams, utils.noop) : streams[0];
|
||||
|
||||
const offListeners = stream.finished(responseStream, () => {
|
||||
offListeners();
|
||||
onFinished();
|
||||
});
|
||||
|
||||
|
||||
const response = {
|
||||
status: res.statusCode,
|
||||
@ -558,7 +752,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
// stream.destroy() emit aborted event before calling reject() on Node.js v16
|
||||
rejected = true;
|
||||
responseStream.destroy();
|
||||
reject(new AxiosError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
||||
abort(new AxiosError('maxContentLength size of ' + config.maxContentLength + ' exceeded',
|
||||
AxiosError.ERR_BAD_RESPONSE, config, lastRequest));
|
||||
}
|
||||
});
|
||||
@ -600,7 +794,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
});
|
||||
}
|
||||
|
||||
emitter.once('abort', err => {
|
||||
abortEmitter.once('abort', err => {
|
||||
if (!responseStream.destroyed) {
|
||||
responseStream.emit('error', err);
|
||||
responseStream.destroy();
|
||||
@ -608,9 +802,12 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
});
|
||||
});
|
||||
|
||||
emitter.once('abort', err => {
|
||||
reject(err);
|
||||
req.destroy(err);
|
||||
abortEmitter.once('abort', err => {
|
||||
if (req.close) {
|
||||
req.close();
|
||||
} else {
|
||||
req.destroy(err);
|
||||
}
|
||||
});
|
||||
|
||||
// Handle errors
|
||||
@ -632,7 +829,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
const timeout = parseInt(config.timeout, 10);
|
||||
|
||||
if (Number.isNaN(timeout)) {
|
||||
reject(new AxiosError(
|
||||
abort(new AxiosError(
|
||||
'error trying to parse `config.timeout` to int',
|
||||
AxiosError.ERR_BAD_OPTION_VALUE,
|
||||
config,
|
||||
@ -654,14 +851,16 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
if (config.timeoutErrorMessage) {
|
||||
timeoutErrorMessage = config.timeoutErrorMessage;
|
||||
}
|
||||
reject(new AxiosError(
|
||||
abort(new AxiosError(
|
||||
timeoutErrorMessage,
|
||||
transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
|
||||
config,
|
||||
req
|
||||
));
|
||||
abort();
|
||||
});
|
||||
} else {
|
||||
// explicitly reset the socket timeout value for a possible `keep-alive` request
|
||||
req.setTimeout(0);
|
||||
}
|
||||
|
||||
|
||||
@ -687,7 +886,8 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
||||
|
||||
data.pipe(req);
|
||||
} else {
|
||||
req.end(data);
|
||||
data && req.write(data);
|
||||
req.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
19
node_modules/axios/lib/adapters/xhr.js
generated
vendored
19
node_modules/axios/lib/adapters/xhr.js
generated
vendored
@ -104,15 +104,18 @@ export default isXHRAdapterSupported && function (config) {
|
||||
};
|
||||
|
||||
// Handle low level network errors
|
||||
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));
|
||||
|
||||
// Clean up request
|
||||
request = null;
|
||||
request.onerror = function handleError(event) {
|
||||
// Browsers deliver a ProgressEvent in XHR onerror
|
||||
// (message may be empty; when present, surface it)
|
||||
// See https://developer.mozilla.org/docs/Web/API/XMLHttpRequest/error_event
|
||||
const msg = event && event.message ? event.message : 'Network Error';
|
||||
const err = new AxiosError(msg, AxiosError.ERR_NETWORK, config, request);
|
||||
// attach the underlying event for consumers who want details
|
||||
err.event = event || null;
|
||||
reject(err);
|
||||
request = null;
|
||||
};
|
||||
|
||||
|
||||
// Handle timeout
|
||||
request.ontimeout = function handleTimeout() {
|
||||
let timeoutErrorMessage = _config.timeout ? 'timeout of ' + _config.timeout + 'ms exceeded' : 'timeout exceeded';
|
||||
|
||||
6
node_modules/axios/lib/core/Axios.js
generated
vendored
6
node_modules/axios/lib/core/Axios.js
generated
vendored
@ -153,8 +153,8 @@ class Axios {
|
||||
|
||||
if (!synchronousRequestInterceptors) {
|
||||
const chain = [dispatchRequest.bind(this), undefined];
|
||||
chain.unshift.apply(chain, requestInterceptorChain);
|
||||
chain.push.apply(chain, responseInterceptorChain);
|
||||
chain.unshift(...requestInterceptorChain);
|
||||
chain.push(...responseInterceptorChain);
|
||||
len = chain.length;
|
||||
|
||||
promise = Promise.resolve(config);
|
||||
@ -170,8 +170,6 @@ class Axios {
|
||||
|
||||
let newConfig = config;
|
||||
|
||||
i = 0;
|
||||
|
||||
while (i < len) {
|
||||
const onFulfilled = requestInterceptorChain[i++];
|
||||
const onRejected = requestInterceptorChain[i++];
|
||||
|
||||
13
node_modules/axios/lib/core/AxiosError.js
generated
vendored
13
node_modules/axios/lib/core/AxiosError.js
generated
vendored
@ -89,11 +89,18 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
|
||||
return prop !== 'isAxiosError';
|
||||
});
|
||||
|
||||
AxiosError.call(axiosError, error.message, code, config, request, response);
|
||||
const msg = error && error.message ? error.message : 'Error';
|
||||
|
||||
axiosError.cause = error;
|
||||
// Prefer explicit code; otherwise copy the low-level error's code (e.g. ECONNREFUSED)
|
||||
const errCode = code == null && error ? error.code : code;
|
||||
AxiosError.call(axiosError, msg, errCode, config, request, response);
|
||||
|
||||
axiosError.name = error.name;
|
||||
// Chain the original error on the standard field; non-enumerable to avoid JSON noise
|
||||
if (error && axiosError.cause == null) {
|
||||
Object.defineProperty(axiosError, 'cause', { value: error, configurable: true });
|
||||
}
|
||||
|
||||
axiosError.name = (error && error.name) || 'Error';
|
||||
|
||||
customProps && Object.assign(axiosError, customProps);
|
||||
|
||||
|
||||
2
node_modules/axios/lib/core/InterceptorManager.js
generated
vendored
2
node_modules/axios/lib/core/InterceptorManager.js
generated
vendored
@ -30,7 +30,7 @@ class InterceptorManager {
|
||||
*
|
||||
* @param {Number} id The ID that was returned by `use`
|
||||
*
|
||||
* @returns {Boolean} `true` if the interceptor was removed, `false` otherwise
|
||||
* @returns {void}
|
||||
*/
|
||||
eject(id) {
|
||||
if (this.handlers[id]) {
|
||||
|
||||
2
node_modules/axios/lib/core/dispatchRequest.js
generated
vendored
2
node_modules/axios/lib/core/dispatchRequest.js
generated
vendored
@ -46,7 +46,7 @@ export default function dispatchRequest(config) {
|
||||
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
||||
}
|
||||
|
||||
const adapter = adapters.getAdapter(config.adapter || defaults.adapter);
|
||||
const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
|
||||
|
||||
return adapter(config).then(function onAdapterResolution(response) {
|
||||
throwIfCancellationRequested(config);
|
||||
|
||||
10
node_modules/axios/lib/core/mergeConfig.js
generated
vendored
10
node_modules/axios/lib/core/mergeConfig.js
generated
vendored
@ -31,11 +31,11 @@ export default function mergeConfig(config1, config2) {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line consistent-return
|
||||
function mergeDeepProperties(a, b, prop , caseless) {
|
||||
function mergeDeepProperties(a, b, prop, caseless) {
|
||||
if (!utils.isUndefined(b)) {
|
||||
return getMergedValue(a, b, prop , caseless);
|
||||
return getMergedValue(a, b, prop, caseless);
|
||||
} else if (!utils.isUndefined(a)) {
|
||||
return getMergedValue(undefined, a, prop , caseless);
|
||||
return getMergedValue(undefined, a, prop, caseless);
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,10 +93,10 @@ export default function mergeConfig(config1, config2) {
|
||||
socketPath: defaultToConfig2,
|
||||
responseEncoding: defaultToConfig2,
|
||||
validateStatus: mergeDirectKeys,
|
||||
headers: (a, b , prop) => mergeDeepProperties(headersToObject(a), headersToObject(b),prop, true)
|
||||
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
|
||||
};
|
||||
|
||||
utils.forEach(Object.keys(Object.assign({}, config1, config2)), function computeConfigValue(prop) {
|
||||
utils.forEach(Object.keys({...config1, ...config2}), function computeConfigValue(prop) {
|
||||
const merge = mergeMap[prop] || mergeDeepProperties;
|
||||
const configValue = merge(config1[prop], config2[prop], prop);
|
||||
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
||||
|
||||
2
node_modules/axios/lib/defaults/index.js
generated
vendored
2
node_modules/axios/lib/defaults/index.js
generated
vendored
@ -111,7 +111,7 @@ const defaults = {
|
||||
const strictJSONParsing = !silentJSONParsing && JSONRequested;
|
||||
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
return JSON.parse(data, this.parseReviver);
|
||||
} catch (e) {
|
||||
if (strictJSONParsing) {
|
||||
if (e.name === 'SyntaxError') {
|
||||
|
||||
2
node_modules/axios/lib/env/data.js
generated
vendored
2
node_modules/axios/lib/env/data.js
generated
vendored
@ -1 +1 @@
|
||||
export const VERSION = "1.9.0";
|
||||
export const VERSION = "1.13.2";
|
||||
6
node_modules/axios/lib/helpers/HttpStatusCode.js
generated
vendored
6
node_modules/axios/lib/helpers/HttpStatusCode.js
generated
vendored
@ -62,6 +62,12 @@ const HttpStatusCode = {
|
||||
LoopDetected: 508,
|
||||
NotExtended: 510,
|
||||
NetworkAuthenticationRequired: 511,
|
||||
WebServerIsDown: 521,
|
||||
ConnectionTimedOut: 522,
|
||||
OriginIsUnreachable: 523,
|
||||
TimeoutOccurred: 524,
|
||||
SslHandshakeFailed: 525,
|
||||
InvalidSslCertificate: 526,
|
||||
};
|
||||
|
||||
Object.entries(HttpStatusCode).forEach(([key, value]) => {
|
||||
|
||||
7
node_modules/axios/lib/helpers/bind.js
generated
vendored
7
node_modules/axios/lib/helpers/bind.js
generated
vendored
@ -1,5 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Create a bound version of a function with a specified `this` context
|
||||
*
|
||||
* @param {Function} fn - The function to bind
|
||||
* @param {*} thisArg - The value to be passed as the `this` parameter
|
||||
* @returns {Function} A new function that will call the original function with the specified `this` context
|
||||
*/
|
||||
export default function bind(fn, thisArg) {
|
||||
return function wrap() {
|
||||
return fn.apply(thisArg, arguments);
|
||||
|
||||
4
node_modules/axios/lib/helpers/buildURL.js
generated
vendored
4
node_modules/axios/lib/helpers/buildURL.js
generated
vendored
@ -16,9 +16,7 @@ function encode(val) {
|
||||
replace(/%3A/gi, ':').
|
||||
replace(/%24/g, '$').
|
||||
replace(/%2C/gi, ',').
|
||||
replace(/%20/g, '+').
|
||||
replace(/%5B/gi, '[').
|
||||
replace(/%5D/gi, ']');
|
||||
replace(/%20/g, '+');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
33
node_modules/axios/lib/helpers/cookies.js
generated
vendored
33
node_modules/axios/lib/helpers/cookies.js
generated
vendored
@ -5,27 +5,38 @@ export default platform.hasStandardBrowserEnv ?
|
||||
|
||||
// Standard browser envs support document.cookie
|
||||
{
|
||||
write(name, value, expires, path, domain, secure) {
|
||||
const cookie = [name + '=' + encodeURIComponent(value)];
|
||||
write(name, value, expires, path, domain, secure, sameSite) {
|
||||
if (typeof document === 'undefined') return;
|
||||
|
||||
utils.isNumber(expires) && cookie.push('expires=' + new Date(expires).toGMTString());
|
||||
const cookie = [`${name}=${encodeURIComponent(value)}`];
|
||||
|
||||
utils.isString(path) && cookie.push('path=' + path);
|
||||
|
||||
utils.isString(domain) && cookie.push('domain=' + domain);
|
||||
|
||||
secure === true && cookie.push('secure');
|
||||
if (utils.isNumber(expires)) {
|
||||
cookie.push(`expires=${new Date(expires).toUTCString()}`);
|
||||
}
|
||||
if (utils.isString(path)) {
|
||||
cookie.push(`path=${path}`);
|
||||
}
|
||||
if (utils.isString(domain)) {
|
||||
cookie.push(`domain=${domain}`);
|
||||
}
|
||||
if (secure === true) {
|
||||
cookie.push('secure');
|
||||
}
|
||||
if (utils.isString(sameSite)) {
|
||||
cookie.push(`SameSite=${sameSite}`);
|
||||
}
|
||||
|
||||
document.cookie = cookie.join('; ');
|
||||
},
|
||||
|
||||
read(name) {
|
||||
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
|
||||
return (match ? decodeURIComponent(match[3]) : null);
|
||||
if (typeof document === 'undefined') return null;
|
||||
const match = document.cookie.match(new RegExp('(?:^|; )' + name + '=([^;]*)'));
|
||||
return match ? decodeURIComponent(match[1]) : null;
|
||||
},
|
||||
|
||||
remove(name) {
|
||||
this.write(name, '', Date.now() - 86400000);
|
||||
this.write(name, '', Date.now() - 86400000, '/');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
73
node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js
generated
vendored
Normal file
73
node_modules/axios/lib/helpers/estimateDataURLDecodedBytes.js
generated
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
/**
|
||||
* Estimate decoded byte length of a data:// URL *without* allocating large buffers.
|
||||
* - For base64: compute exact decoded size using length and padding;
|
||||
* handle %XX at the character-count level (no string allocation).
|
||||
* - For non-base64: use UTF-8 byteLength of the encoded body as a safe upper bound.
|
||||
*
|
||||
* @param {string} url
|
||||
* @returns {number}
|
||||
*/
|
||||
export default function estimateDataURLDecodedBytes(url) {
|
||||
if (!url || typeof url !== 'string') return 0;
|
||||
if (!url.startsWith('data:')) return 0;
|
||||
|
||||
const comma = url.indexOf(',');
|
||||
if (comma < 0) return 0;
|
||||
|
||||
const meta = url.slice(5, comma);
|
||||
const body = url.slice(comma + 1);
|
||||
const isBase64 = /;base64/i.test(meta);
|
||||
|
||||
if (isBase64) {
|
||||
let effectiveLen = body.length;
|
||||
const len = body.length; // cache length
|
||||
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (body.charCodeAt(i) === 37 /* '%' */ && i + 2 < len) {
|
||||
const a = body.charCodeAt(i + 1);
|
||||
const b = body.charCodeAt(i + 2);
|
||||
const isHex =
|
||||
((a >= 48 && a <= 57) || (a >= 65 && a <= 70) || (a >= 97 && a <= 102)) &&
|
||||
((b >= 48 && b <= 57) || (b >= 65 && b <= 70) || (b >= 97 && b <= 102));
|
||||
|
||||
if (isHex) {
|
||||
effectiveLen -= 2;
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let pad = 0;
|
||||
let idx = len - 1;
|
||||
|
||||
const tailIsPct3D = (j) =>
|
||||
j >= 2 &&
|
||||
body.charCodeAt(j - 2) === 37 && // '%'
|
||||
body.charCodeAt(j - 1) === 51 && // '3'
|
||||
(body.charCodeAt(j) === 68 || body.charCodeAt(j) === 100); // 'D' or 'd'
|
||||
|
||||
if (idx >= 0) {
|
||||
if (body.charCodeAt(idx) === 61 /* '=' */) {
|
||||
pad++;
|
||||
idx--;
|
||||
} else if (tailIsPct3D(idx)) {
|
||||
pad++;
|
||||
idx -= 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (pad === 1 && idx >= 0) {
|
||||
if (body.charCodeAt(idx) === 61 /* '=' */) {
|
||||
pad++;
|
||||
} else if (tailIsPct3D(idx)) {
|
||||
pad++;
|
||||
}
|
||||
}
|
||||
|
||||
const groups = Math.floor(effectiveLen / 4);
|
||||
const bytes = groups * 3 - (pad || 0);
|
||||
return bytes > 0 ? bytes : 0;
|
||||
}
|
||||
|
||||
return Buffer.byteLength(body, 'utf8');
|
||||
}
|
||||
22
node_modules/axios/lib/helpers/resolveConfig.js
generated
vendored
22
node_modules/axios/lib/helpers/resolveConfig.js
generated
vendored
@ -10,7 +10,7 @@ import buildURL from "./buildURL.js";
|
||||
export default (config) => {
|
||||
const newConfig = mergeConfig({}, config);
|
||||
|
||||
let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
|
||||
let { data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth } = newConfig;
|
||||
|
||||
newConfig.headers = headers = AxiosHeaders.from(headers);
|
||||
|
||||
@ -23,17 +23,21 @@ export default (config) => {
|
||||
);
|
||||
}
|
||||
|
||||
let contentType;
|
||||
|
||||
if (utils.isFormData(data)) {
|
||||
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
||||
headers.setContentType(undefined); // Let the browser set it
|
||||
} else if ((contentType = headers.getContentType()) !== false) {
|
||||
// fix semicolon duplication issue for ReactNative FormData implementation
|
||||
const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
|
||||
headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
|
||||
headers.setContentType(undefined); // browser handles it
|
||||
} else if (utils.isFunction(data.getHeaders)) {
|
||||
// Node.js FormData (like form-data package)
|
||||
const formHeaders = data.getHeaders();
|
||||
// Only set safe headers to avoid overwriting security headers
|
||||
const allowedHeaders = ['content-type', 'content-length'];
|
||||
Object.entries(formHeaders).forEach(([key, val]) => {
|
||||
if (allowedHeaders.includes(key.toLowerCase())) {
|
||||
headers.set(key, val);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add xsrf header
|
||||
// This is only done if running in a standard browser environment.
|
||||
|
||||
2
node_modules/axios/lib/helpers/throttle.js
generated
vendored
2
node_modules/axios/lib/helpers/throttle.js
generated
vendored
@ -17,7 +17,7 @@ function throttle(fn, freq) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
fn.apply(null, args);
|
||||
fn(...args);
|
||||
}
|
||||
|
||||
const throttled = (...args) => {
|
||||
|
||||
4
node_modules/axios/lib/helpers/toFormData.js
generated
vendored
4
node_modules/axios/lib/helpers/toFormData.js
generated
vendored
@ -120,6 +120,10 @@ function toFormData(obj, formData, options) {
|
||||
return value.toISOString();
|
||||
}
|
||||
|
||||
if (utils.isBoolean(value)) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
if (!useBlob && utils.isBlob(value)) {
|
||||
throw new AxiosError('Blob is not supported. Use a Buffer instead.');
|
||||
}
|
||||
|
||||
7
node_modules/axios/lib/helpers/toURLEncodedForm.js
generated
vendored
7
node_modules/axios/lib/helpers/toURLEncodedForm.js
generated
vendored
@ -5,7 +5,7 @@ import toFormData from './toFormData.js';
|
||||
import platform from '../platform/index.js';
|
||||
|
||||
export default function toURLEncodedForm(data, options) {
|
||||
return toFormData(data, new platform.classes.URLSearchParams(), Object.assign({
|
||||
return toFormData(data, new platform.classes.URLSearchParams(), {
|
||||
visitor: function(value, key, path, helpers) {
|
||||
if (platform.isNode && utils.isBuffer(value)) {
|
||||
this.append(key, value.toString('base64'));
|
||||
@ -13,6 +13,7 @@ export default function toURLEncodedForm(data, options) {
|
||||
}
|
||||
|
||||
return helpers.defaultVisitor.apply(this, arguments);
|
||||
}
|
||||
}, options));
|
||||
},
|
||||
...options
|
||||
});
|
||||
}
|
||||
|
||||
42
node_modules/axios/lib/utils.js
generated
vendored
42
node_modules/axios/lib/utils.js
generated
vendored
@ -136,6 +136,27 @@ const isPlainObject = (val) => {
|
||||
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(toStringTag in val) && !(iterator in val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is an empty object (safely handles Buffers)
|
||||
*
|
||||
* @param {*} val The value to test
|
||||
*
|
||||
* @returns {boolean} True if value is an empty object, otherwise false
|
||||
*/
|
||||
const isEmptyObject = (val) => {
|
||||
// Early return for non-objects or Buffers to prevent RangeError
|
||||
if (!isObject(val) || isBuffer(val)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
||||
} catch (e) {
|
||||
// Fallback for any other objects that might cause RangeError with Object.keys()
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a value is a Date
|
||||
*
|
||||
@ -258,6 +279,11 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
||||
fn.call(null, obj[i], i, obj);
|
||||
}
|
||||
} else {
|
||||
// Buffer check
|
||||
if (isBuffer(obj)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Iterate over object keys
|
||||
const keys = allOwnKeys ? Object.getOwnPropertyNames(obj) : Object.keys(obj);
|
||||
const len = keys.length;
|
||||
@ -271,6 +297,10 @@ function forEach(obj, fn, {allOwnKeys = false} = {}) {
|
||||
}
|
||||
|
||||
function findKey(obj, key) {
|
||||
if (isBuffer(obj)){
|
||||
return null;
|
||||
}
|
||||
|
||||
key = key.toLowerCase();
|
||||
const keys = Object.keys(obj);
|
||||
let i = keys.length;
|
||||
@ -311,7 +341,7 @@ const isContextDefined = (context) => !isUndefined(context) && context !== _glob
|
||||
* @returns {Object} Result of all merge properties
|
||||
*/
|
||||
function merge(/* obj1, obj2, obj3, ... */) {
|
||||
const {caseless} = isContextDefined(this) && this || {};
|
||||
const {caseless, skipUndefined} = isContextDefined(this) && this || {};
|
||||
const result = {};
|
||||
const assignValue = (val, key) => {
|
||||
const targetKey = caseless && findKey(result, key) || key;
|
||||
@ -321,7 +351,7 @@ function merge(/* obj1, obj2, obj3, ... */) {
|
||||
result[targetKey] = merge({}, val);
|
||||
} else if (isArray(val)) {
|
||||
result[targetKey] = val.slice();
|
||||
} else {
|
||||
} else if (!skipUndefined || !isUndefined(val)) {
|
||||
result[targetKey] = val;
|
||||
}
|
||||
}
|
||||
@ -603,6 +633,8 @@ const toFiniteNumber = (value, defaultValue) => {
|
||||
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* If the thing is a FormData object, return true, otherwise return false.
|
||||
*
|
||||
@ -624,6 +656,11 @@ const toJSONObject = (obj) => {
|
||||
return;
|
||||
}
|
||||
|
||||
//Buffer check
|
||||
if (isBuffer(source)) {
|
||||
return source;
|
||||
}
|
||||
|
||||
if(!('toJSON' in source)) {
|
||||
stack[i] = source;
|
||||
const target = isArray(source) ? [] : {};
|
||||
@ -695,6 +732,7 @@ export default {
|
||||
isBoolean,
|
||||
isObject,
|
||||
isPlainObject,
|
||||
isEmptyObject,
|
||||
isReadableStream,
|
||||
isRequest,
|
||||
isResponse,
|
||||
|
||||
Reference in New Issue
Block a user