@wiajs/req 1.7.28 → 1.7.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node/req.cjs +124 -119
- package/dist/req.js +66 -63
- package/dist/req.min.js +3 -3
- package/dist/web/req.cjs +1911 -2397
- package/dist/web/req.mjs +1917 -2421
- package/lib/adapters/http.js +48 -40
- package/lib/adapters/xhr.js +3 -3
- package/lib/cancel/CancelToken.js +40 -40
- package/lib/core/Axios.js +11 -11
- package/lib/core/AxiosHeaders.js +3 -3
- package/lib/core/InterceptorManager.js +3 -3
- package/lib/helpers/AxiosTransformStream.js +34 -34
- package/lib/helpers/formDataToStream.js +18 -18
- package/lib/platform/node/classes/URLSearchParams.js +1 -1
- package/package.json +226 -214
package/dist/node/req.cjs
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @wia/req v1.7.
|
|
3
|
-
* (c) 2024 Sibyl Yu, Matt Zabriskie and contributors
|
|
2
|
+
* @wia/req v1.7.30
|
|
3
|
+
* (c) 2024-2025 Sibyl Yu, Matt Zabriskie and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
8
|
const FormData$1 = require('form-data');
|
|
9
|
-
const url = require('
|
|
10
|
-
const request = require('@wiajs/request');
|
|
9
|
+
const url = require('url');
|
|
11
10
|
const agent = require('@wiajs/agent');
|
|
12
11
|
const log$1 = require('@wiajs/log');
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
12
|
+
const request = require('@wiajs/request');
|
|
13
|
+
const util = require('util');
|
|
14
|
+
const events = require('events');
|
|
16
15
|
const stream = require('stream');
|
|
17
|
-
const
|
|
16
|
+
const zlib = require('zlib');
|
|
18
17
|
|
|
19
18
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
20
19
|
function bind(fn, thisArg) {
|
|
@@ -2023,32 +2022,6 @@ utils$1.inherits(CanceledError, AxiosError, {
|
|
|
2023
2022
|
__CANCEL__: true
|
|
2024
2023
|
});
|
|
2025
2024
|
|
|
2026
|
-
/**
|
|
2027
|
-
* Resolve or reject a Promise based on response status.
|
|
2028
|
-
*
|
|
2029
|
-
* @param {Function} resolve A function that resolves the promise.
|
|
2030
|
-
* @param {Function} reject A function that rejects the promise.
|
|
2031
|
-
* @param {object} response The response.
|
|
2032
|
-
*
|
|
2033
|
-
* @returns {object} The response.
|
|
2034
|
-
*/
|
|
2035
|
-
function settle(resolve, reject, response) {
|
|
2036
|
-
const validateStatus = response.config.validateStatus;
|
|
2037
|
-
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
|
2038
|
-
resolve(response);
|
|
2039
|
-
} else {
|
|
2040
|
-
reject(
|
|
2041
|
-
new AxiosError(
|
|
2042
|
-
'Request failed with status code ' + response.status,
|
|
2043
|
-
[AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
|
2044
|
-
response.config,
|
|
2045
|
-
response.request,
|
|
2046
|
-
response
|
|
2047
|
-
)
|
|
2048
|
-
);
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
|
|
2052
2025
|
/**
|
|
2053
2026
|
* Determines whether the specified URL is absolute
|
|
2054
2027
|
*
|
|
@@ -2094,61 +2067,34 @@ function buildFullPath(baseURL, requestedURL) {
|
|
|
2094
2067
|
return requestedURL;
|
|
2095
2068
|
}
|
|
2096
2069
|
|
|
2097
|
-
const VERSION = "1.7.7";
|
|
2098
|
-
|
|
2099
|
-
function parseProtocol(url) {
|
|
2100
|
-
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
|
2101
|
-
return match && match[1] || '';
|
|
2102
|
-
}
|
|
2103
|
-
|
|
2104
|
-
const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
|
|
2105
|
-
|
|
2106
2070
|
/**
|
|
2107
|
-
*
|
|
2071
|
+
* Resolve or reject a Promise based on response status.
|
|
2108
2072
|
*
|
|
2109
|
-
* @param {
|
|
2110
|
-
* @param {
|
|
2111
|
-
* @param {
|
|
2112
|
-
* @param {?Function} options.Blob
|
|
2073
|
+
* @param {Function} resolve A function that resolves the promise.
|
|
2074
|
+
* @param {Function} reject A function that rejects the promise.
|
|
2075
|
+
* @param {object} response The response.
|
|
2113
2076
|
*
|
|
2114
|
-
* @returns {
|
|
2077
|
+
* @returns {object} The response.
|
|
2115
2078
|
*/
|
|
2116
|
-
function
|
|
2117
|
-
const
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
|
|
2131
|
-
}
|
|
2132
|
-
|
|
2133
|
-
const mime = match[1];
|
|
2134
|
-
const isBase64 = match[2];
|
|
2135
|
-
const body = match[3];
|
|
2136
|
-
const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
|
|
2137
|
-
|
|
2138
|
-
if (asBlob) {
|
|
2139
|
-
if (!_Blob) {
|
|
2140
|
-
throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
|
|
2141
|
-
}
|
|
2142
|
-
|
|
2143
|
-
return new _Blob([buffer], {type: mime});
|
|
2144
|
-
}
|
|
2145
|
-
|
|
2146
|
-
return buffer;
|
|
2079
|
+
function settle(resolve, reject, response) {
|
|
2080
|
+
const validateStatus = response.config.validateStatus;
|
|
2081
|
+
if (!response.status || !validateStatus || validateStatus(response.status)) {
|
|
2082
|
+
resolve(response);
|
|
2083
|
+
} else {
|
|
2084
|
+
reject(
|
|
2085
|
+
new AxiosError(
|
|
2086
|
+
'Request failed with status code ' + response.status,
|
|
2087
|
+
[AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
|
|
2088
|
+
response.config,
|
|
2089
|
+
response.request,
|
|
2090
|
+
response
|
|
2091
|
+
)
|
|
2092
|
+
);
|
|
2147
2093
|
}
|
|
2148
|
-
|
|
2149
|
-
throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
|
|
2150
2094
|
}
|
|
2151
2095
|
|
|
2096
|
+
const VERSION = "1.7.7";
|
|
2097
|
+
|
|
2152
2098
|
const kInternals = Symbol('internals');
|
|
2153
2099
|
|
|
2154
2100
|
class AxiosTransformStream extends stream.Transform {
|
|
@@ -2286,6 +2232,19 @@ class AxiosTransformStream extends stream.Transform {
|
|
|
2286
2232
|
}
|
|
2287
2233
|
}
|
|
2288
2234
|
|
|
2235
|
+
const callbackify = (fn, reducer) => {
|
|
2236
|
+
return utils$1.isAsyncFn(fn) ? function (...args) {
|
|
2237
|
+
const cb = args.pop();
|
|
2238
|
+
fn.apply(this, args).then((value) => {
|
|
2239
|
+
try {
|
|
2240
|
+
reducer ? cb(null, ...reducer(value)) : cb(null, value);
|
|
2241
|
+
} catch (err) {
|
|
2242
|
+
cb(err);
|
|
2243
|
+
}
|
|
2244
|
+
}, cb);
|
|
2245
|
+
} : fn;
|
|
2246
|
+
};
|
|
2247
|
+
|
|
2289
2248
|
const {asyncIterator} = Symbol;
|
|
2290
2249
|
|
|
2291
2250
|
const readBlob = async function* (blob) {
|
|
@@ -2320,7 +2279,7 @@ class FormDataPart {
|
|
|
2320
2279
|
if (isStringValue) {
|
|
2321
2280
|
value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
|
|
2322
2281
|
} else {
|
|
2323
|
-
headers += `Content-Type: ${value.type ||
|
|
2282
|
+
headers += `Content-Type: ${value.type || 'application/octet-stream'}${CRLF}`;
|
|
2324
2283
|
}
|
|
2325
2284
|
|
|
2326
2285
|
this.headers = textEncoder.encode(headers + CRLF);
|
|
@@ -2333,12 +2292,12 @@ class FormDataPart {
|
|
|
2333
2292
|
this.value = value;
|
|
2334
2293
|
}
|
|
2335
2294
|
|
|
2336
|
-
async *encode(){
|
|
2295
|
+
async *encode() {
|
|
2337
2296
|
yield this.headers;
|
|
2338
2297
|
|
|
2339
2298
|
const {value} = this;
|
|
2340
2299
|
|
|
2341
|
-
if(utils$1.isTypedArray(value)) {
|
|
2300
|
+
if (utils$1.isTypedArray(value)) {
|
|
2342
2301
|
yield value;
|
|
2343
2302
|
} else {
|
|
2344
2303
|
yield* readBlob(value);
|
|
@@ -2348,11 +2307,15 @@ class FormDataPart {
|
|
|
2348
2307
|
}
|
|
2349
2308
|
|
|
2350
2309
|
static escapeName(name) {
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2310
|
+
return String(name).replace(
|
|
2311
|
+
/[\r\n"]/g,
|
|
2312
|
+
match =>
|
|
2313
|
+
({
|
|
2314
|
+
'\r': '%0D',
|
|
2315
|
+
'\n': '%0A',
|
|
2316
|
+
'"': '%22',
|
|
2317
|
+
})[match]
|
|
2318
|
+
)
|
|
2356
2319
|
}
|
|
2357
2320
|
}
|
|
2358
2321
|
|
|
@@ -2360,11 +2323,11 @@ const formDataToStream = (form, headersHandler, options) => {
|
|
|
2360
2323
|
const {
|
|
2361
2324
|
tag = 'form-data-boundary',
|
|
2362
2325
|
size = 25,
|
|
2363
|
-
boundary = tag + '-' + utils$1.generateString(size, BOUNDARY_ALPHABET)
|
|
2326
|
+
boundary = tag + '-' + utils$1.generateString(size, BOUNDARY_ALPHABET),
|
|
2364
2327
|
} = options || {};
|
|
2365
2328
|
|
|
2366
|
-
if(!utils$1.isFormData(form)) {
|
|
2367
|
-
throw TypeError('FormData instance required')
|
|
2329
|
+
if (!utils$1.isFormData(form)) {
|
|
2330
|
+
throw TypeError('FormData instance required')
|
|
2368
2331
|
}
|
|
2369
2332
|
|
|
2370
2333
|
if (boundary.length < 1 || boundary.length > 70) {
|
|
@@ -2378,7 +2341,7 @@ const formDataToStream = (form, headersHandler, options) => {
|
|
|
2378
2341
|
const parts = Array.from(form.entries()).map(([name, value]) => {
|
|
2379
2342
|
const part = new FormDataPart(name, value);
|
|
2380
2343
|
contentLength += part.size;
|
|
2381
|
-
return part
|
|
2344
|
+
return part
|
|
2382
2345
|
});
|
|
2383
2346
|
|
|
2384
2347
|
contentLength += boundaryBytes.byteLength * parts.length;
|
|
@@ -2386,7 +2349,7 @@ const formDataToStream = (form, headersHandler, options) => {
|
|
|
2386
2349
|
contentLength = utils$1.toFiniteNumber(contentLength);
|
|
2387
2350
|
|
|
2388
2351
|
const computedHeaders = {
|
|
2389
|
-
'Content-Type': `multipart/form-data; boundary=${boundary}
|
|
2352
|
+
'Content-Type': `multipart/form-data; boundary=${boundary}`,
|
|
2390
2353
|
};
|
|
2391
2354
|
|
|
2392
2355
|
if (Number.isFinite(contentLength)) {
|
|
@@ -2395,28 +2358,70 @@ const formDataToStream = (form, headersHandler, options) => {
|
|
|
2395
2358
|
|
|
2396
2359
|
headersHandler && headersHandler(computedHeaders);
|
|
2397
2360
|
|
|
2398
|
-
return stream.Readable.from(
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2361
|
+
return stream.Readable.from(
|
|
2362
|
+
(async function* () {
|
|
2363
|
+
for (const part of parts) {
|
|
2364
|
+
yield boundaryBytes;
|
|
2365
|
+
yield* part.encode();
|
|
2366
|
+
}
|
|
2403
2367
|
|
|
2404
|
-
|
|
2405
|
-
|
|
2368
|
+
yield footerBytes;
|
|
2369
|
+
})()
|
|
2370
|
+
)
|
|
2406
2371
|
};
|
|
2407
2372
|
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2373
|
+
function parseProtocol(url) {
|
|
2374
|
+
const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
|
|
2375
|
+
return match && match[1] || '';
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
const DATA_URL_PATTERN = /^(?:([^;]+);)?(?:[^;]+;)?(base64|),([\s\S]*)$/;
|
|
2379
|
+
|
|
2380
|
+
/**
|
|
2381
|
+
* Parse data uri to a Buffer or Blob
|
|
2382
|
+
*
|
|
2383
|
+
* @param {String} uri
|
|
2384
|
+
* @param {?Boolean} asBlob
|
|
2385
|
+
* @param {?Object} options
|
|
2386
|
+
* @param {?Function} options.Blob
|
|
2387
|
+
*
|
|
2388
|
+
* @returns {Buffer|Blob}
|
|
2389
|
+
*/
|
|
2390
|
+
function fromDataURI(uri, asBlob, options) {
|
|
2391
|
+
const _Blob = options && options.Blob || platform.classes.Blob;
|
|
2392
|
+
const protocol = parseProtocol(uri);
|
|
2393
|
+
|
|
2394
|
+
if (asBlob === undefined && _Blob) {
|
|
2395
|
+
asBlob = true;
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
if (protocol === 'data') {
|
|
2399
|
+
uri = protocol.length ? uri.slice(protocol.length + 1) : uri;
|
|
2400
|
+
|
|
2401
|
+
const match = DATA_URL_PATTERN.exec(uri);
|
|
2402
|
+
|
|
2403
|
+
if (!match) {
|
|
2404
|
+
throw new AxiosError('Invalid URL', AxiosError.ERR_INVALID_URL);
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
const mime = match[1];
|
|
2408
|
+
const isBase64 = match[2];
|
|
2409
|
+
const body = match[3];
|
|
2410
|
+
const buffer = Buffer.from(decodeURIComponent(body), isBase64 ? 'base64' : 'utf8');
|
|
2411
|
+
|
|
2412
|
+
if (asBlob) {
|
|
2413
|
+
if (!_Blob) {
|
|
2414
|
+
throw new AxiosError('Blob is not supported', AxiosError.ERR_NOT_SUPPORT);
|
|
2416
2415
|
}
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
}
|
|
2416
|
+
|
|
2417
|
+
return new _Blob([buffer], {type: mime});
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2420
|
+
return buffer;
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
throw new AxiosError('Unsupported protocol ' + protocol, AxiosError.ERR_NOT_SUPPORT);
|
|
2424
|
+
}
|
|
2420
2425
|
|
|
2421
2426
|
/**
|
|
2422
2427
|
* Calculate data maxRate
|
|
@@ -2590,7 +2595,7 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils$1.kindOf(
|
|
|
2590
2595
|
|
|
2591
2596
|
/**
|
|
2592
2597
|
* !+++
|
|
2593
|
-
* 将request
|
|
2598
|
+
* 将request 函数改为类,request 拆分为 init 初始化和 请求执行,
|
|
2594
2599
|
* 如需重新发起请求时,无需重新初始化
|
|
2595
2600
|
*/
|
|
2596
2601
|
class HttpAdapter {
|
|
@@ -2616,7 +2621,7 @@ class HttpAdapter {
|
|
|
2616
2621
|
constructor(config) {
|
|
2617
2622
|
this.config = config;
|
|
2618
2623
|
// temporary internal emitter until the AxiosRequest class will be implemented
|
|
2619
|
-
this.emitter = new
|
|
2624
|
+
this.emitter = new events.EventEmitter();
|
|
2620
2625
|
}
|
|
2621
2626
|
|
|
2622
2627
|
/**
|
|
@@ -2798,7 +2803,7 @@ class HttpAdapter {
|
|
|
2798
2803
|
} else if (utils$1.isBlob(data)) {
|
|
2799
2804
|
data.size && headers.setContentType(data.type || 'application/octet-stream');
|
|
2800
2805
|
headers.setContentLength(data.size || 0);
|
|
2801
|
-
data = stream
|
|
2806
|
+
data = stream.Readable.from(readBlob(data));
|
|
2802
2807
|
} else if (data && !utils$1.isStream(data)) {
|
|
2803
2808
|
if (Buffer.isBuffer(data)) ; else if (utils$1.isArrayBuffer(data)) {
|
|
2804
2809
|
data = Buffer.from(new Uint8Array(data));
|
|
@@ -2838,10 +2843,10 @@ class HttpAdapter {
|
|
|
2838
2843
|
|
|
2839
2844
|
if (data && (onUploadProgress || maxUploadRate)) {
|
|
2840
2845
|
if (!utils$1.isStream(data)) {
|
|
2841
|
-
data = stream
|
|
2846
|
+
data = stream.Readable.from(data, {objectMode: false});
|
|
2842
2847
|
}
|
|
2843
2848
|
|
|
2844
|
-
data = stream
|
|
2849
|
+
data = stream.pipeline(
|
|
2845
2850
|
[
|
|
2846
2851
|
data,
|
|
2847
2852
|
new AxiosTransformStream({
|
|
@@ -3001,7 +3006,7 @@ class HttpAdapter {
|
|
|
3001
3006
|
convertedData = utils$1.stripBOM(convertedData);
|
|
3002
3007
|
}
|
|
3003
3008
|
} else if (responseType === 'stream') {
|
|
3004
|
-
convertedData = stream
|
|
3009
|
+
convertedData = stream.Readable.from(convertedData);
|
|
3005
3010
|
}
|
|
3006
3011
|
|
|
3007
3012
|
// 返回响应
|
package/dist/req.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @wia/req v1.7.
|
|
3
|
-
* (c) 2024 Sibyl Yu, Matt Zabriskie and contributors
|
|
2
|
+
* @wia/req v1.7.30
|
|
3
|
+
* (c) 2024-2025 Sibyl Yu, Matt Zabriskie and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
(function (global, factory) {
|
|
@@ -998,9 +998,6 @@
|
|
|
998
998
|
}
|
|
999
999
|
|
|
1000
1000
|
let InterceptorManager = class InterceptorManager {
|
|
1001
|
-
constructor(){
|
|
1002
|
-
this.handlers = [];
|
|
1003
|
-
}
|
|
1004
1001
|
/**
|
|
1005
1002
|
* Add a new interceptor to the stack
|
|
1006
1003
|
*
|
|
@@ -1053,6 +1050,9 @@
|
|
|
1053
1050
|
}
|
|
1054
1051
|
});
|
|
1055
1052
|
}
|
|
1053
|
+
constructor(){
|
|
1054
|
+
this.handlers = [];
|
|
1055
|
+
}
|
|
1056
1056
|
};
|
|
1057
1057
|
var InterceptorManager$1 = InterceptorManager;
|
|
1058
1058
|
|
|
@@ -1793,8 +1793,11 @@
|
|
|
1793
1793
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
1794
1794
|
}
|
|
1795
1795
|
|
|
1796
|
+
/* eslint-env browser */
|
|
1797
|
+
|
|
1796
1798
|
var browser = typeof self == 'object' ? self.FormData : window.FormData;
|
|
1797
|
-
|
|
1799
|
+
|
|
1800
|
+
var FormData$2 = /*@__PURE__*/getDefaultExportFromCjs(browser);
|
|
1798
1801
|
|
|
1799
1802
|
/**
|
|
1800
1803
|
* Determines if the given thing is a array or js object.
|
|
@@ -2421,9 +2424,6 @@
|
|
|
2421
2424
|
});
|
|
2422
2425
|
}
|
|
2423
2426
|
let AxiosHeaders = class AxiosHeaders {
|
|
2424
|
-
constructor(headers){
|
|
2425
|
-
headers && this.set(headers);
|
|
2426
|
-
}
|
|
2427
2427
|
/**
|
|
2428
2428
|
*
|
|
2429
2429
|
* @param {*} header
|
|
@@ -2582,6 +2582,9 @@
|
|
|
2582
2582
|
utils$2.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|
2583
2583
|
return this;
|
|
2584
2584
|
}
|
|
2585
|
+
constructor(headers){
|
|
2586
|
+
headers && this.set(headers);
|
|
2587
|
+
}
|
|
2585
2588
|
};
|
|
2586
2589
|
AxiosHeaders.accessor([
|
|
2587
2590
|
'Content-Type',
|
|
@@ -2686,12 +2689,12 @@
|
|
|
2686
2689
|
|
|
2687
2690
|
const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
|
|
2688
2691
|
let XhrAdapter = class XhrAdapter {
|
|
2689
|
-
constructor(config){
|
|
2690
|
-
this.init(config);
|
|
2691
|
-
}
|
|
2692
2692
|
init(config) {}
|
|
2693
2693
|
request() {}
|
|
2694
2694
|
stream() {}
|
|
2695
|
+
constructor(config){
|
|
2696
|
+
this.init(config);
|
|
2697
|
+
}
|
|
2695
2698
|
};
|
|
2696
2699
|
var XhrAdapter$1 = isXHRAdapterSupported && XhrAdapter;
|
|
2697
2700
|
|
|
@@ -3004,17 +3007,6 @@
|
|
|
3004
3007
|
*
|
|
3005
3008
|
* @return {Axios} A new instance of Axios
|
|
3006
3009
|
*/ let Axios = class Axios {
|
|
3007
|
-
constructor(instanceConfig){
|
|
3008
|
-
this.defaults = instanceConfig;
|
|
3009
|
-
this.config = this.defaults // !+++
|
|
3010
|
-
;
|
|
3011
|
-
this.interceptors = {
|
|
3012
|
-
request: new InterceptorManager$1(),
|
|
3013
|
-
response: new InterceptorManager$1()
|
|
3014
|
-
};
|
|
3015
|
-
this.init() // !+++
|
|
3016
|
-
;
|
|
3017
|
-
}
|
|
3018
3010
|
/**
|
|
3019
3011
|
* !+++
|
|
3020
3012
|
* config 属性直接挂在到实例上,方便读取、设置、修改
|
|
@@ -3264,6 +3256,17 @@
|
|
|
3264
3256
|
const fullPath = buildFullPath(config.baseURL, config.url);
|
|
3265
3257
|
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
3266
3258
|
}
|
|
3259
|
+
constructor(instanceConfig){
|
|
3260
|
+
this.defaults = instanceConfig;
|
|
3261
|
+
this.config = this.defaults // !+++
|
|
3262
|
+
;
|
|
3263
|
+
this.interceptors = {
|
|
3264
|
+
request: new InterceptorManager$1(),
|
|
3265
|
+
response: new InterceptorManager$1()
|
|
3266
|
+
};
|
|
3267
|
+
this.init() // !+++
|
|
3268
|
+
;
|
|
3269
|
+
}
|
|
3267
3270
|
};
|
|
3268
3271
|
// Provide aliases for supported request methods
|
|
3269
3272
|
utils$2.forEach([
|
|
@@ -3354,46 +3357,6 @@
|
|
|
3354
3357
|
*
|
|
3355
3358
|
* @returns {CancelToken}
|
|
3356
3359
|
*/ let CancelToken = class CancelToken {
|
|
3357
|
-
constructor(executor){
|
|
3358
|
-
if (typeof executor !== 'function') {
|
|
3359
|
-
throw new TypeError('executor must be a function.');
|
|
3360
|
-
}
|
|
3361
|
-
let resolvePromise;
|
|
3362
|
-
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
3363
|
-
resolvePromise = resolve;
|
|
3364
|
-
});
|
|
3365
|
-
const token = this;
|
|
3366
|
-
// eslint-disable-next-line func-names
|
|
3367
|
-
this.promise.then((cancel)=>{
|
|
3368
|
-
if (!token._listeners) return;
|
|
3369
|
-
let i = token._listeners.length;
|
|
3370
|
-
while(i-- > 0){
|
|
3371
|
-
token._listeners[i](cancel);
|
|
3372
|
-
}
|
|
3373
|
-
token._listeners = null;
|
|
3374
|
-
});
|
|
3375
|
-
// eslint-disable-next-line func-names
|
|
3376
|
-
this.promise.then = (onfulfilled)=>{
|
|
3377
|
-
let _resolve;
|
|
3378
|
-
// eslint-disable-next-line func-names
|
|
3379
|
-
const promise = new Promise((resolve)=>{
|
|
3380
|
-
token.subscribe(resolve);
|
|
3381
|
-
_resolve = resolve;
|
|
3382
|
-
}).then(onfulfilled);
|
|
3383
|
-
promise.cancel = function reject() {
|
|
3384
|
-
token.unsubscribe(_resolve);
|
|
3385
|
-
};
|
|
3386
|
-
return promise;
|
|
3387
|
-
};
|
|
3388
|
-
executor(function cancel(message, config, request) {
|
|
3389
|
-
if (token.reason) {
|
|
3390
|
-
// Cancellation has already been requested
|
|
3391
|
-
return;
|
|
3392
|
-
}
|
|
3393
|
-
token.reason = new CanceledError(message, config, request);
|
|
3394
|
-
resolvePromise(token.reason);
|
|
3395
|
-
});
|
|
3396
|
-
}
|
|
3397
3360
|
/**
|
|
3398
3361
|
* Throws a `CanceledError` if cancellation has been requested.
|
|
3399
3362
|
*/ throwIfRequested() {
|
|
@@ -3449,6 +3412,46 @@
|
|
|
3449
3412
|
cancel
|
|
3450
3413
|
};
|
|
3451
3414
|
}
|
|
3415
|
+
constructor(executor){
|
|
3416
|
+
if (typeof executor !== 'function') {
|
|
3417
|
+
throw new TypeError('executor must be a function.');
|
|
3418
|
+
}
|
|
3419
|
+
let resolvePromise;
|
|
3420
|
+
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
3421
|
+
resolvePromise = resolve;
|
|
3422
|
+
});
|
|
3423
|
+
const token = this;
|
|
3424
|
+
// eslint-disable-next-line func-names
|
|
3425
|
+
this.promise.then((cancel)=>{
|
|
3426
|
+
if (!token._listeners) return;
|
|
3427
|
+
let i = token._listeners.length;
|
|
3428
|
+
while(i-- > 0){
|
|
3429
|
+
token._listeners[i](cancel);
|
|
3430
|
+
}
|
|
3431
|
+
token._listeners = null;
|
|
3432
|
+
});
|
|
3433
|
+
// eslint-disable-next-line func-names
|
|
3434
|
+
this.promise.then = (onfulfilled)=>{
|
|
3435
|
+
let _resolve;
|
|
3436
|
+
// eslint-disable-next-line func-names
|
|
3437
|
+
const promise = new Promise((resolve)=>{
|
|
3438
|
+
token.subscribe(resolve);
|
|
3439
|
+
_resolve = resolve;
|
|
3440
|
+
}).then(onfulfilled);
|
|
3441
|
+
promise.cancel = function reject() {
|
|
3442
|
+
token.unsubscribe(_resolve);
|
|
3443
|
+
};
|
|
3444
|
+
return promise;
|
|
3445
|
+
};
|
|
3446
|
+
executor(function cancel(message, config, request) {
|
|
3447
|
+
if (token.reason) {
|
|
3448
|
+
// Cancellation has already been requested
|
|
3449
|
+
return;
|
|
3450
|
+
}
|
|
3451
|
+
token.reason = new CanceledError(message, config, request);
|
|
3452
|
+
resolvePromise(token.reason);
|
|
3453
|
+
});
|
|
3454
|
+
}
|
|
3452
3455
|
};
|
|
3453
3456
|
var CancelToken$1 = CancelToken;
|
|
3454
3457
|
|