@wiajs/req 1.7.11 → 1.7.13
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 +254 -101
- package/dist/req.js +1626 -20285
- package/dist/req.min.js +2 -2
- package/dist/web/req.cjs +1702 -20719
- package/dist/web/req.mjs +2795 -1356
- package/index.d.cts +7 -3
- package/index.d.ts +7 -3
- package/lib/adapters/http.js +23 -8
- package/package.json +9 -9
- package/dist/node/req.mjs +0 -3550
package/dist/node/req.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @wia/req v1.7.
|
|
2
|
+
* @wia/req v1.7.13
|
|
3
3
|
* (c) 2024 Sibyl Yu, Matt Zabriskie and contributors
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
const FormData$1 = require('form-data');
|
|
9
9
|
const url = require('node:url');
|
|
10
10
|
const request = require('@wiajs/request');
|
|
11
|
-
const
|
|
11
|
+
const agent = require('@wiajs/agent');
|
|
12
12
|
const log$1 = require('@wiajs/log');
|
|
13
13
|
const util = require('node:util');
|
|
14
14
|
const zlib = require('node:zlib');
|
|
@@ -1284,9 +1284,7 @@ class InterceptorManager {
|
|
|
1284
1284
|
}
|
|
1285
1285
|
});
|
|
1286
1286
|
}
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
const InterceptorManager$1 = InterceptorManager;
|
|
1287
|
+
}
|
|
1290
1288
|
|
|
1291
1289
|
const transitionalDefaults = {
|
|
1292
1290
|
silentJSONParsing: true,
|
|
@@ -1615,9 +1613,7 @@ const defaults = {
|
|
|
1615
1613
|
|
|
1616
1614
|
utils$1.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
|
|
1617
1615
|
defaults.headers[method] = {};
|
|
1618
|
-
});
|
|
1619
|
-
|
|
1620
|
-
const defaults$1 = defaults;
|
|
1616
|
+
});
|
|
1621
1617
|
|
|
1622
1618
|
// RawAxiosHeaders whose duplicates are ignored by node
|
|
1623
1619
|
// c.f. https://nodejs.org/api/http.html#http_message_headers
|
|
@@ -1979,9 +1975,7 @@ utils$1.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
|
|
|
1979
1975
|
};
|
|
1980
1976
|
});
|
|
1981
1977
|
|
|
1982
|
-
utils$1.freezeMethods(AxiosHeaders);
|
|
1983
|
-
|
|
1984
|
-
const AxiosHeaders$1 = AxiosHeaders;
|
|
1978
|
+
utils$1.freezeMethods(AxiosHeaders);
|
|
1985
1979
|
|
|
1986
1980
|
/**
|
|
1987
1981
|
* Transform the data for a request or a response
|
|
@@ -1992,9 +1986,9 @@ const AxiosHeaders$1 = AxiosHeaders;
|
|
|
1992
1986
|
* @returns {*} The resulting transformed data
|
|
1993
1987
|
*/
|
|
1994
1988
|
function transformData(fns, response) {
|
|
1995
|
-
const config = this || defaults
|
|
1989
|
+
const config = this || defaults;
|
|
1996
1990
|
const context = response || config;
|
|
1997
|
-
const headers = AxiosHeaders
|
|
1991
|
+
const headers = AxiosHeaders.from(context.headers);
|
|
1998
1992
|
let data = context.data;
|
|
1999
1993
|
|
|
2000
1994
|
utils$1.forEach(fns, function transform(fn) {
|
|
@@ -2290,9 +2284,7 @@ class AxiosTransformStream extends stream.Transform {
|
|
|
2290
2284
|
}
|
|
2291
2285
|
});
|
|
2292
2286
|
}
|
|
2293
|
-
}
|
|
2294
|
-
|
|
2295
|
-
const AxiosTransformStream$1 = AxiosTransformStream;
|
|
2287
|
+
}
|
|
2296
2288
|
|
|
2297
2289
|
const {asyncIterator} = Symbol;
|
|
2298
2290
|
|
|
@@ -2306,9 +2298,7 @@ const readBlob = async function* (blob) {
|
|
|
2306
2298
|
} else {
|
|
2307
2299
|
yield blob;
|
|
2308
2300
|
}
|
|
2309
|
-
};
|
|
2310
|
-
|
|
2311
|
-
const readBlob$1 = readBlob;
|
|
2301
|
+
};
|
|
2312
2302
|
|
|
2313
2303
|
const BOUNDARY_ALPHABET = utils$1.ALPHABET.ALPHA_DIGIT + '-_';
|
|
2314
2304
|
|
|
@@ -2351,7 +2341,7 @@ class FormDataPart {
|
|
|
2351
2341
|
if(utils$1.isTypedArray(value)) {
|
|
2352
2342
|
yield value;
|
|
2353
2343
|
} else {
|
|
2354
|
-
yield* readBlob
|
|
2344
|
+
yield* readBlob(value);
|
|
2355
2345
|
}
|
|
2356
2346
|
|
|
2357
2347
|
yield CRLF_BYTES;
|
|
@@ -2413,9 +2403,7 @@ const formDataToStream = (form, headersHandler, options) => {
|
|
|
2413
2403
|
|
|
2414
2404
|
yield footerBytes;
|
|
2415
2405
|
})());
|
|
2416
|
-
};
|
|
2417
|
-
|
|
2418
|
-
const formDataToStream$1 = formDataToStream;
|
|
2406
|
+
};
|
|
2419
2407
|
|
|
2420
2408
|
const callbackify = (fn, reducer) => {
|
|
2421
2409
|
return utils$1.isAsyncFn(fn) ? function (...args) {
|
|
@@ -2428,9 +2416,7 @@ const callbackify = (fn, reducer) => {
|
|
|
2428
2416
|
}
|
|
2429
2417
|
}, cb);
|
|
2430
2418
|
} : fn;
|
|
2431
|
-
};
|
|
2432
|
-
|
|
2433
|
-
const callbackify$1 = callbackify;
|
|
2419
|
+
};
|
|
2434
2420
|
|
|
2435
2421
|
/**
|
|
2436
2422
|
* Calculate data maxRate
|
|
@@ -2593,9 +2579,7 @@ const asyncDecorator =
|
|
|
2593
2579
|
(...args) =>
|
|
2594
2580
|
utils$1.asap(() => fn(...args));
|
|
2595
2581
|
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
const log = log$1.log({env: `wia:req:${log$1.name((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('req.cjs', document.baseURI).href)))}`});
|
|
2582
|
+
const log = log$1.log({env: `wia:req:${log$1.name((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('req.cjs', document.baseURI).href)))}`});
|
|
2599
2583
|
|
|
2600
2584
|
const isBrotliSupported = utils$1.isFunction(zlib.createBrotliDecompress);
|
|
2601
2585
|
|
|
@@ -2610,20 +2594,20 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils$1.kindOf(
|
|
|
2610
2594
|
* 如需重新发起请求时,无需重新初始化
|
|
2611
2595
|
*/
|
|
2612
2596
|
class HttpAdapter {
|
|
2613
|
-
isDone = false
|
|
2614
|
-
rejected = false
|
|
2597
|
+
isDone = false
|
|
2598
|
+
rejected = false
|
|
2615
2599
|
/** @type {*} */
|
|
2616
|
-
req = null
|
|
2600
|
+
req = null
|
|
2617
2601
|
/** @type {*} */
|
|
2618
|
-
config = null
|
|
2602
|
+
config = null
|
|
2619
2603
|
/** @type {number} */
|
|
2620
|
-
maxUploadRate
|
|
2604
|
+
maxUploadRate
|
|
2621
2605
|
/** @type {number} */
|
|
2622
|
-
maxDownloadRate
|
|
2606
|
+
maxDownloadRate
|
|
2623
2607
|
/** @type {*} */
|
|
2624
|
-
data = null
|
|
2608
|
+
data = null
|
|
2625
2609
|
/** @type {*} */
|
|
2626
|
-
transport = null
|
|
2610
|
+
transport = null
|
|
2627
2611
|
|
|
2628
2612
|
/**
|
|
2629
2613
|
*
|
|
@@ -2649,7 +2633,7 @@ class HttpAdapter {
|
|
|
2649
2633
|
code === 204 ||
|
|
2650
2634
|
// Not Modified
|
|
2651
2635
|
code === 304
|
|
2652
|
-
)
|
|
2636
|
+
)
|
|
2653
2637
|
}
|
|
2654
2638
|
|
|
2655
2639
|
/**
|
|
@@ -2657,7 +2641,10 @@ class HttpAdapter {
|
|
|
2657
2641
|
* @param {*} reason
|
|
2658
2642
|
*/
|
|
2659
2643
|
abort(reason) {
|
|
2660
|
-
this.emitter.emit(
|
|
2644
|
+
this.emitter.emit(
|
|
2645
|
+
'abort',
|
|
2646
|
+
!reason || reason.type ? new CanceledError(null, this.config, this.req) : reason
|
|
2647
|
+
);
|
|
2661
2648
|
}
|
|
2662
2649
|
|
|
2663
2650
|
onFinished() {
|
|
@@ -2689,7 +2676,7 @@ class HttpAdapter {
|
|
|
2689
2676
|
* @returns
|
|
2690
2677
|
*/
|
|
2691
2678
|
done(value, isRejected) {
|
|
2692
|
-
if (this.isDone) return
|
|
2679
|
+
if (this.isDone) return
|
|
2693
2680
|
this.isDone = true;
|
|
2694
2681
|
this?.onDone(value, isRejected);
|
|
2695
2682
|
}
|
|
@@ -2708,7 +2695,10 @@ class HttpAdapter {
|
|
|
2708
2695
|
_.method = method;
|
|
2709
2696
|
|
|
2710
2697
|
if (lookup) {
|
|
2711
|
-
const _lookup = callbackify
|
|
2698
|
+
const _lookup = callbackify(
|
|
2699
|
+
lookup,
|
|
2700
|
+
/** @param {*} value */ value => (utils$1.isArray(value) ? value : [value])
|
|
2701
|
+
);
|
|
2712
2702
|
// hotfix to support opt.all option which is required for node 20.x
|
|
2713
2703
|
/**
|
|
2714
2704
|
* @param {string} hostname
|
|
@@ -2717,7 +2707,7 @@ class HttpAdapter {
|
|
|
2717
2707
|
*/
|
|
2718
2708
|
lookup = (hostname, opt, cb) => {
|
|
2719
2709
|
_lookup(hostname, opt, (err, arg0, arg1) => {
|
|
2720
|
-
if (err) return cb(err)
|
|
2710
|
+
if (err) return cb(err)
|
|
2721
2711
|
|
|
2722
2712
|
const addresses = utils$1.isArray(arg0)
|
|
2723
2713
|
? arg0.map(addr => buildAddressEntry(addr))
|
|
@@ -2755,18 +2745,20 @@ class HttpAdapter {
|
|
|
2755
2745
|
|
|
2756
2746
|
throw new AxiosError(
|
|
2757
2747
|
`Request failed with status code ${response.status}`,
|
|
2758
|
-
[AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][
|
|
2748
|
+
[AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][
|
|
2749
|
+
Math.floor(response.status / 100) - 4
|
|
2750
|
+
],
|
|
2759
2751
|
response.config,
|
|
2760
2752
|
response.request,
|
|
2761
2753
|
response
|
|
2762
|
-
)
|
|
2754
|
+
)
|
|
2763
2755
|
}
|
|
2764
2756
|
|
|
2765
2757
|
if (supportedProtocols.indexOf(protocol) === -1) {
|
|
2766
|
-
throw new AxiosError(`Unsupported protocol ${protocol}`, AxiosError.ERR_BAD_REQUEST, config)
|
|
2758
|
+
throw new AxiosError(`Unsupported protocol ${protocol}`, AxiosError.ERR_BAD_REQUEST, config)
|
|
2767
2759
|
}
|
|
2768
2760
|
|
|
2769
|
-
const headers = AxiosHeaders
|
|
2761
|
+
const headers = AxiosHeaders.from(config.headers).normalize();
|
|
2770
2762
|
|
|
2771
2763
|
// Set User-Agent (required by some servers)
|
|
2772
2764
|
// See https://github.com/axios/axios/issues/69
|
|
@@ -2785,10 +2777,14 @@ class HttpAdapter {
|
|
|
2785
2777
|
if (utils$1.isSpecCompliantForm(data)) {
|
|
2786
2778
|
const userBoundary = headers.getContentType(/boundary=([-_\w\d]{10,70})/i);
|
|
2787
2779
|
|
|
2788
|
-
data = formDataToStream
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2780
|
+
data = formDataToStream(
|
|
2781
|
+
data,
|
|
2782
|
+
/** @param {*} formHeaders */ formHeaders => headers.set(formHeaders),
|
|
2783
|
+
{
|
|
2784
|
+
tag: `axios-${VERSION}-boundary`,
|
|
2785
|
+
boundary: userBoundary?.[1] || undefined,
|
|
2786
|
+
}
|
|
2787
|
+
);
|
|
2792
2788
|
// support for https://www.npmjs.com/package/form-data api
|
|
2793
2789
|
} else if (utils$1.isFormData(data) && utils$1.isFunction(data.getHeaders)) {
|
|
2794
2790
|
headers.set(data.getHeaders());
|
|
@@ -2802,7 +2798,7 @@ class HttpAdapter {
|
|
|
2802
2798
|
} else if (utils$1.isBlob(data)) {
|
|
2803
2799
|
data.size && headers.setContentType(data.type || 'application/octet-stream');
|
|
2804
2800
|
headers.setContentLength(data.size || 0);
|
|
2805
|
-
data = stream$1.Readable.from(readBlob
|
|
2801
|
+
data = stream$1.Readable.from(readBlob(data));
|
|
2806
2802
|
} else if (data && !utils$1.isStream(data)) {
|
|
2807
2803
|
if (Buffer.isBuffer(data)) ; else if (utils$1.isArrayBuffer(data)) {
|
|
2808
2804
|
data = Buffer.from(new Uint8Array(data));
|
|
@@ -2813,14 +2809,18 @@ class HttpAdapter {
|
|
|
2813
2809
|
'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
|
|
2814
2810
|
AxiosError.ERR_BAD_REQUEST,
|
|
2815
2811
|
config
|
|
2816
|
-
)
|
|
2812
|
+
)
|
|
2817
2813
|
}
|
|
2818
2814
|
|
|
2819
2815
|
// Add Content-Length header if data exists
|
|
2820
2816
|
headers.setContentLength(data.length, false);
|
|
2821
2817
|
|
|
2822
2818
|
if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
|
|
2823
|
-
throw new AxiosError(
|
|
2819
|
+
throw new AxiosError(
|
|
2820
|
+
'Request body larger than maxBodyLength limit',
|
|
2821
|
+
AxiosError.ERR_BAD_REQUEST,
|
|
2822
|
+
config
|
|
2823
|
+
)
|
|
2824
2824
|
}
|
|
2825
2825
|
}
|
|
2826
2826
|
|
|
@@ -2844,7 +2844,7 @@ class HttpAdapter {
|
|
|
2844
2844
|
data = stream$1.pipeline(
|
|
2845
2845
|
[
|
|
2846
2846
|
data,
|
|
2847
|
-
new AxiosTransformStream
|
|
2847
|
+
new AxiosTransformStream({
|
|
2848
2848
|
maxRate: utils$1.toFiniteNumber(maxUploadRate),
|
|
2849
2849
|
}),
|
|
2850
2850
|
],
|
|
@@ -2856,7 +2856,10 @@ class HttpAdapter {
|
|
|
2856
2856
|
'progress',
|
|
2857
2857
|
flushOnFinish(
|
|
2858
2858
|
data,
|
|
2859
|
-
progressEventDecorator(
|
|
2859
|
+
progressEventDecorator(
|
|
2860
|
+
contentLength,
|
|
2861
|
+
progressEventReducer(asyncDecorator(onUploadProgress), false, 3)
|
|
2862
|
+
)
|
|
2860
2863
|
)
|
|
2861
2864
|
);
|
|
2862
2865
|
}
|
|
@@ -2880,29 +2883,40 @@ class HttpAdapter {
|
|
|
2880
2883
|
let path;
|
|
2881
2884
|
|
|
2882
2885
|
try {
|
|
2883
|
-
path = buildURL(
|
|
2886
|
+
path = buildURL(
|
|
2887
|
+
parsed.pathname + parsed.search,
|
|
2888
|
+
config.params,
|
|
2889
|
+
config.paramsSerializer
|
|
2890
|
+
).replace(/^\?/, '');
|
|
2884
2891
|
} catch (err) {
|
|
2885
2892
|
/** @type {*} */
|
|
2886
2893
|
const customErr = new Error(err.message);
|
|
2887
2894
|
customErr.config = config;
|
|
2888
2895
|
customErr.url = config.url;
|
|
2889
2896
|
customErr.exists = true;
|
|
2890
|
-
throw customErr
|
|
2897
|
+
throw customErr
|
|
2891
2898
|
}
|
|
2892
2899
|
|
|
2893
|
-
headers.set(
|
|
2900
|
+
headers.set(
|
|
2901
|
+
'Accept-Encoding',
|
|
2902
|
+
`gzip, compress, deflate${isBrotliSupported ? ', br' : ''}`,
|
|
2903
|
+
false
|
|
2904
|
+
);
|
|
2894
2905
|
|
|
2895
2906
|
/** @type {*} */
|
|
2896
2907
|
const options = {
|
|
2897
2908
|
path,
|
|
2898
2909
|
method,
|
|
2899
2910
|
headers: headers.toJSON(),
|
|
2900
|
-
agents: {http: config.httpAgent, https: config.httpsAgent},
|
|
2911
|
+
// agents: {http: config.httpAgent, https: config.httpsAgent},
|
|
2912
|
+
agents,
|
|
2901
2913
|
auth,
|
|
2902
2914
|
protocol,
|
|
2903
2915
|
family,
|
|
2904
2916
|
beforeRedirect: dispatchBeforeRedirect,
|
|
2905
2917
|
beforeRedirects: {},
|
|
2918
|
+
http,
|
|
2919
|
+
https,
|
|
2906
2920
|
};
|
|
2907
2921
|
|
|
2908
2922
|
// cacheable-lookup integration hotfix
|
|
@@ -2910,16 +2924,19 @@ class HttpAdapter {
|
|
|
2910
2924
|
|
|
2911
2925
|
if (config.socketPath) options.socketPath = config.socketPath;
|
|
2912
2926
|
else {
|
|
2913
|
-
options.hostname = parsed.hostname.startsWith('[')
|
|
2927
|
+
options.hostname = parsed.hostname.startsWith('[')
|
|
2928
|
+
? parsed.hostname.slice(1, -1)
|
|
2929
|
+
: parsed.hostname;
|
|
2914
2930
|
options.port = parsed.port;
|
|
2915
2931
|
// ! proxy 配置了 agent,否则使用缺省 agent
|
|
2916
|
-
if (config.agent) options.agents = new Agent(config.agent);
|
|
2932
|
+
if (config.agent) options.agents = new agent.Agent(config.agent);
|
|
2917
2933
|
}
|
|
2918
2934
|
|
|
2919
2935
|
// 执行请求的具体对象
|
|
2920
2936
|
_.transport = config.transport;
|
|
2921
2937
|
|
|
2922
2938
|
const isHttpsRequest = isHttps.test(options.protocol);
|
|
2939
|
+
// agents 优先于 agent,在 request中根据协议从 agents 中获取
|
|
2923
2940
|
options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
|
|
2924
2941
|
|
|
2925
2942
|
if (config.maxBodyLength > -1) options.maxBodyLength = config.maxBodyLength;
|
|
@@ -2940,7 +2957,7 @@ class HttpAdapter {
|
|
|
2940
2957
|
_.data = data;
|
|
2941
2958
|
|
|
2942
2959
|
log({config}, 'init');
|
|
2943
|
-
return options
|
|
2960
|
+
return options
|
|
2944
2961
|
}
|
|
2945
2962
|
|
|
2946
2963
|
/**
|
|
@@ -2970,7 +2987,7 @@ class HttpAdapter {
|
|
|
2970
2987
|
Blob: config.env?.Blob,
|
|
2971
2988
|
});
|
|
2972
2989
|
} catch (err) {
|
|
2973
|
-
throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config)
|
|
2990
|
+
throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config)
|
|
2974
2991
|
}
|
|
2975
2992
|
|
|
2976
2993
|
if (responseType === 'text') {
|
|
@@ -2988,13 +3005,13 @@ class HttpAdapter {
|
|
|
2988
3005
|
data: convertedData,
|
|
2989
3006
|
status: 200,
|
|
2990
3007
|
statusText: 'OK',
|
|
2991
|
-
headers: new AxiosHeaders
|
|
3008
|
+
headers: new AxiosHeaders(),
|
|
2992
3009
|
config,
|
|
2993
3010
|
};
|
|
2994
3011
|
} else {
|
|
2995
3012
|
let transformStream;
|
|
2996
3013
|
if (onDownloadProgress || maxDownloadRate) {
|
|
2997
|
-
transformStream = new AxiosTransformStream
|
|
3014
|
+
transformStream = new AxiosTransformStream({
|
|
2998
3015
|
maxRate: utils$1.toFiniteNumber(maxDownloadRate),
|
|
2999
3016
|
});
|
|
3000
3017
|
|
|
@@ -3022,7 +3039,8 @@ class HttpAdapter {
|
|
|
3022
3039
|
// log.debug('request', {options});
|
|
3023
3040
|
const req = transport ? transport.request(options) : request(options);
|
|
3024
3041
|
|
|
3025
|
-
if (!req)
|
|
3042
|
+
if (!req)
|
|
3043
|
+
return reject(new AxiosError('Request failed.', AxiosError.ERR_BAD_REQUEST, config))
|
|
3026
3044
|
|
|
3027
3045
|
_.req = req;
|
|
3028
3046
|
|
|
@@ -3074,7 +3092,7 @@ class HttpAdapter {
|
|
|
3074
3092
|
// And then these socket which be hang up will devouring CPU little by little.
|
|
3075
3093
|
// ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
|
|
3076
3094
|
req.setTimeout(timeout, () => {
|
|
3077
|
-
if (_.isDone) return
|
|
3095
|
+
if (_.isDone) return
|
|
3078
3096
|
|
|
3079
3097
|
let timeoutErrorMessage = config.timeout
|
|
3080
3098
|
? `timeout of ${config.timeout}ms exceeded`
|
|
@@ -3086,7 +3104,9 @@ class HttpAdapter {
|
|
|
3086
3104
|
reject(
|
|
3087
3105
|
new AxiosError(
|
|
3088
3106
|
timeoutErrorMessage,
|
|
3089
|
-
transitional.clarifyTimeoutError
|
|
3107
|
+
transitional.clarifyTimeoutError
|
|
3108
|
+
? AxiosError.ETIMEDOUT
|
|
3109
|
+
: AxiosError.ECONNABORTED,
|
|
3090
3110
|
config,
|
|
3091
3111
|
req
|
|
3092
3112
|
)
|
|
@@ -3110,7 +3130,7 @@ class HttpAdapter {
|
|
|
3110
3130
|
* @param {*} stream
|
|
3111
3131
|
*/
|
|
3112
3132
|
(res, stream) => {
|
|
3113
|
-
if (req.destroyed) return
|
|
3133
|
+
if (req.destroyed) return
|
|
3114
3134
|
|
|
3115
3135
|
// 'transfer-encoding': 'chunked'时,无content-length,axios v1.2 不能自动解压
|
|
3116
3136
|
const responseLength = +res.headers['content-length'];
|
|
@@ -3128,7 +3148,7 @@ class HttpAdapter {
|
|
|
3128
3148
|
const response = {
|
|
3129
3149
|
status: res.statusCode,
|
|
3130
3150
|
statusText: res.statusMessage,
|
|
3131
|
-
headers: new AxiosHeaders
|
|
3151
|
+
headers: new AxiosHeaders(res.headers),
|
|
3132
3152
|
config,
|
|
3133
3153
|
request: lastRequest,
|
|
3134
3154
|
};
|
|
@@ -3151,7 +3171,10 @@ class HttpAdapter {
|
|
|
3151
3171
|
totalResponseBytes += chunk.length;
|
|
3152
3172
|
|
|
3153
3173
|
// make sure the content length is not over the maxContentLength if specified
|
|
3154
|
-
if (
|
|
3174
|
+
if (
|
|
3175
|
+
config.maxContentLength > -1 &&
|
|
3176
|
+
totalResponseBytes > config.maxContentLength
|
|
3177
|
+
) {
|
|
3155
3178
|
// stream.destroy() emit aborted event before calling reject() on Node.js v16
|
|
3156
3179
|
_.rejected = true;
|
|
3157
3180
|
stream.destroy();
|
|
@@ -3168,7 +3191,7 @@ class HttpAdapter {
|
|
|
3168
3191
|
);
|
|
3169
3192
|
|
|
3170
3193
|
stream.on('aborted', function handlerStreamAborted() {
|
|
3171
|
-
if (_.rejected) return
|
|
3194
|
+
if (_.rejected) return
|
|
3172
3195
|
|
|
3173
3196
|
const err = new AxiosError(
|
|
3174
3197
|
`maxContentLength size of ${config.maxContentLength} exceeded`,
|
|
@@ -3181,7 +3204,7 @@ class HttpAdapter {
|
|
|
3181
3204
|
});
|
|
3182
3205
|
|
|
3183
3206
|
stream.on('error', function handleStreamError(err) {
|
|
3184
|
-
if (req.destroyed) return
|
|
3207
|
+
if (req.destroyed) return
|
|
3185
3208
|
reject(AxiosError.from(err, null, config, lastRequest));
|
|
3186
3209
|
});
|
|
3187
3210
|
|
|
@@ -3189,7 +3212,9 @@ class HttpAdapter {
|
|
|
3189
3212
|
stream.on('end', function handleStreamEnd() {
|
|
3190
3213
|
try {
|
|
3191
3214
|
let responseData =
|
|
3192
|
-
responseBuffer.length === 1
|
|
3215
|
+
responseBuffer.length === 1
|
|
3216
|
+
? responseBuffer[0]
|
|
3217
|
+
: Buffer.concat(responseBuffer);
|
|
3193
3218
|
if (responseType !== 'arraybuffer') {
|
|
3194
3219
|
responseData = responseData.toString(responseEncoding);
|
|
3195
3220
|
if (!responseEncoding || responseEncoding === 'utf8') {
|
|
@@ -3247,13 +3272,12 @@ class HttpAdapter {
|
|
|
3247
3272
|
} catch (e) {
|
|
3248
3273
|
log.error(e, 'request');
|
|
3249
3274
|
_.done(e, true);
|
|
3250
|
-
throw e
|
|
3275
|
+
throw e
|
|
3251
3276
|
}
|
|
3252
|
-
return R
|
|
3277
|
+
return R
|
|
3253
3278
|
}
|
|
3254
3279
|
}
|
|
3255
3280
|
|
|
3256
|
-
|
|
3257
3281
|
/**
|
|
3258
3282
|
*
|
|
3259
3283
|
* @param {*} stream
|
|
@@ -3263,7 +3287,7 @@ class HttpAdapter {
|
|
|
3263
3287
|
const flushOnFinish = (stream, [throttled, flush]) => {
|
|
3264
3288
|
stream.on('end', flush).on('error', flush);
|
|
3265
3289
|
|
|
3266
|
-
return throttled
|
|
3290
|
+
return throttled
|
|
3267
3291
|
};
|
|
3268
3292
|
|
|
3269
3293
|
/** @typedef {import('../core/Axios').default} Axios */
|
|
@@ -3290,13 +3314,13 @@ function dispatchBeforeRedirect(options, responseDetails) {
|
|
|
3290
3314
|
*/
|
|
3291
3315
|
function resolveFamily({address, family}) {
|
|
3292
3316
|
if (!utils$1.isString(address)) {
|
|
3293
|
-
throw TypeError('address must be a string')
|
|
3317
|
+
throw TypeError('address must be a string')
|
|
3294
3318
|
}
|
|
3295
3319
|
|
|
3296
3320
|
return {
|
|
3297
3321
|
address,
|
|
3298
3322
|
family: family || (address.indexOf('.') < 0 ? 6 : 4),
|
|
3299
|
-
}
|
|
3323
|
+
}
|
|
3300
3324
|
}
|
|
3301
3325
|
|
|
3302
3326
|
/**
|
|
@@ -3313,6 +3337,69 @@ function buildAddressEntry(address, family) {
|
|
|
3313
3337
|
*/
|
|
3314
3338
|
const HttpAdapter$1 = isHttpAdapterSupported && HttpAdapter;
|
|
3315
3339
|
|
|
3340
|
+
platform.hasStandardBrowserEnv ?
|
|
3341
|
+
|
|
3342
|
+
// Standard browser envs have full support of the APIs needed to test
|
|
3343
|
+
// whether the request URL is of the same origin as current location.
|
|
3344
|
+
(function standardBrowserEnv() {
|
|
3345
|
+
const msie = platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent);
|
|
3346
|
+
const urlParsingNode = document.createElement('a');
|
|
3347
|
+
let originURL;
|
|
3348
|
+
|
|
3349
|
+
/**
|
|
3350
|
+
* Parse a URL to discover its components
|
|
3351
|
+
*
|
|
3352
|
+
* @param {String} url The URL to be parsed
|
|
3353
|
+
* @returns {Object}
|
|
3354
|
+
*/
|
|
3355
|
+
function resolveURL(url) {
|
|
3356
|
+
let href = url;
|
|
3357
|
+
|
|
3358
|
+
if (msie) {
|
|
3359
|
+
// IE needs attribute set twice to normalize properties
|
|
3360
|
+
urlParsingNode.setAttribute('href', href);
|
|
3361
|
+
href = urlParsingNode.href;
|
|
3362
|
+
}
|
|
3363
|
+
|
|
3364
|
+
urlParsingNode.setAttribute('href', href);
|
|
3365
|
+
|
|
3366
|
+
// urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
|
|
3367
|
+
return {
|
|
3368
|
+
href: urlParsingNode.href,
|
|
3369
|
+
protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
|
|
3370
|
+
host: urlParsingNode.host,
|
|
3371
|
+
search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
|
|
3372
|
+
hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
|
|
3373
|
+
hostname: urlParsingNode.hostname,
|
|
3374
|
+
port: urlParsingNode.port,
|
|
3375
|
+
pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
|
|
3376
|
+
urlParsingNode.pathname :
|
|
3377
|
+
'/' + urlParsingNode.pathname
|
|
3378
|
+
};
|
|
3379
|
+
}
|
|
3380
|
+
|
|
3381
|
+
originURL = resolveURL(window.location.href);
|
|
3382
|
+
|
|
3383
|
+
/**
|
|
3384
|
+
* Determine if a URL shares the same origin as the current location
|
|
3385
|
+
*
|
|
3386
|
+
* @param {String} requestURL The URL to test
|
|
3387
|
+
* @returns {boolean} True if URL shares the same origin, otherwise false
|
|
3388
|
+
*/
|
|
3389
|
+
return function isURLSameOrigin(requestURL) {
|
|
3390
|
+
const parsed = (utils$1.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
|
|
3391
|
+
return (parsed.protocol === originURL.protocol &&
|
|
3392
|
+
parsed.host === originURL.host);
|
|
3393
|
+
};
|
|
3394
|
+
})() :
|
|
3395
|
+
|
|
3396
|
+
// Non standard browser envs (web workers, react-native) lack needed support.
|
|
3397
|
+
(function nonStandardBrowserEnv() {
|
|
3398
|
+
return function isURLSameOrigin() {
|
|
3399
|
+
return true;
|
|
3400
|
+
};
|
|
3401
|
+
})();
|
|
3402
|
+
|
|
3316
3403
|
const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
|
|
3317
3404
|
class XhrAdapter {
|
|
3318
3405
|
constructor(config) {
|
|
@@ -3425,7 +3512,7 @@ function dispatchRequest(config) {
|
|
|
3425
3512
|
let R;
|
|
3426
3513
|
throwIfCancellationRequested(config);
|
|
3427
3514
|
|
|
3428
|
-
config.headers = AxiosHeaders
|
|
3515
|
+
config.headers = AxiosHeaders.from(config.headers);
|
|
3429
3516
|
|
|
3430
3517
|
// Transform request data
|
|
3431
3518
|
config.data = transformData.call(config, config.transformRequest);
|
|
@@ -3434,7 +3521,7 @@ function dispatchRequest(config) {
|
|
|
3434
3521
|
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
|
3435
3522
|
}
|
|
3436
3523
|
|
|
3437
|
-
const Adapter = adapters.getAdapter(config.adapter || defaults
|
|
3524
|
+
const Adapter = adapters.getAdapter(config.adapter || defaults.adapter);
|
|
3438
3525
|
const adapter = new Adapter(config);
|
|
3439
3526
|
|
|
3440
3527
|
if (config.stream) R = adapter.request(this);
|
|
@@ -3453,7 +3540,7 @@ function dispatchRequest(config) {
|
|
|
3453
3540
|
});
|
|
3454
3541
|
// if (response.data && !response.body) response.body = response.data
|
|
3455
3542
|
|
|
3456
|
-
response.headers = AxiosHeaders
|
|
3543
|
+
response.headers = AxiosHeaders.from(response.headers);
|
|
3457
3544
|
|
|
3458
3545
|
return response
|
|
3459
3546
|
},
|
|
@@ -3466,7 +3553,7 @@ function dispatchRequest(config) {
|
|
|
3466
3553
|
reason.response.data = transformData.call(config, config.transformResponse, reason.response);
|
|
3467
3554
|
// body === data
|
|
3468
3555
|
if (reason.response.data && !reason.response.body) reason.response.body = reason.response.data;
|
|
3469
|
-
reason.response.headers = AxiosHeaders
|
|
3556
|
+
reason.response.headers = AxiosHeaders.from(reason.response.headers);
|
|
3470
3557
|
}
|
|
3471
3558
|
}
|
|
3472
3559
|
|
|
@@ -3477,7 +3564,7 @@ function dispatchRequest(config) {
|
|
|
3477
3564
|
return R
|
|
3478
3565
|
}
|
|
3479
3566
|
|
|
3480
|
-
const headersToObject = (thing) => thing instanceof AxiosHeaders
|
|
3567
|
+
const headersToObject = (thing) => thing instanceof AxiosHeaders ? { ...thing } : thing;
|
|
3481
3568
|
|
|
3482
3569
|
/**
|
|
3483
3570
|
* Config-specific merge-function which creates a new config-object
|
|
@@ -3688,8 +3775,8 @@ class Axios {
|
|
|
3688
3775
|
this.defaults = instanceConfig;
|
|
3689
3776
|
this.config = this.defaults; // !+++
|
|
3690
3777
|
this.interceptors = {
|
|
3691
|
-
request: new InterceptorManager
|
|
3692
|
-
response: new InterceptorManager
|
|
3778
|
+
request: new InterceptorManager(),
|
|
3779
|
+
response: new InterceptorManager(),
|
|
3693
3780
|
};
|
|
3694
3781
|
|
|
3695
3782
|
this.init(); // !+++
|
|
@@ -3876,7 +3963,7 @@ class Axios {
|
|
|
3876
3963
|
});
|
|
3877
3964
|
|
|
3878
3965
|
// 源值存在,则不覆盖,contextHeaders 优先于 headers
|
|
3879
|
-
config.headers = AxiosHeaders
|
|
3966
|
+
config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
|
3880
3967
|
|
|
3881
3968
|
// filter out skipped interceptors
|
|
3882
3969
|
const requestInterceptorChain = []; // 请求拦截器,hook
|
|
@@ -4065,9 +4152,7 @@ utils$1.forEach(['posts', 'puts', 'patchs'], function forEachMethodWithData(meth
|
|
|
4065
4152
|
Axios.prototype[method] = generateStreamMethod();
|
|
4066
4153
|
|
|
4067
4154
|
Axios.prototype[`${method}Forms`] = generateStreamMethod(true);
|
|
4068
|
-
});
|
|
4069
|
-
|
|
4070
|
-
const Axios$1 = Axios;
|
|
4155
|
+
});
|
|
4071
4156
|
|
|
4072
4157
|
/**
|
|
4073
4158
|
* A `CancelToken` is an object that can be used to request cancellation of an operation.
|
|
@@ -4197,9 +4282,7 @@ class CancelToken {
|
|
|
4197
4282
|
cancel
|
|
4198
4283
|
};
|
|
4199
4284
|
}
|
|
4200
|
-
}
|
|
4201
|
-
|
|
4202
|
-
const CancelToken$1 = CancelToken;
|
|
4285
|
+
}
|
|
4203
4286
|
|
|
4204
4287
|
/**
|
|
4205
4288
|
* Syntactic sugar for invoking a function and expanding an array for arguments.
|
|
@@ -4239,6 +4322,76 @@ function isAxiosError(payload) {
|
|
|
4239
4322
|
return utils$1.isObject(payload) && (payload.isAxiosError === true);
|
|
4240
4323
|
}
|
|
4241
4324
|
|
|
4325
|
+
const HttpStatusCode = {
|
|
4326
|
+
Continue: 100,
|
|
4327
|
+
SwitchingProtocols: 101,
|
|
4328
|
+
Processing: 102,
|
|
4329
|
+
EarlyHints: 103,
|
|
4330
|
+
Ok: 200,
|
|
4331
|
+
Created: 201,
|
|
4332
|
+
Accepted: 202,
|
|
4333
|
+
NonAuthoritativeInformation: 203,
|
|
4334
|
+
NoContent: 204,
|
|
4335
|
+
ResetContent: 205,
|
|
4336
|
+
PartialContent: 206,
|
|
4337
|
+
MultiStatus: 207,
|
|
4338
|
+
AlreadyReported: 208,
|
|
4339
|
+
ImUsed: 226,
|
|
4340
|
+
MultipleChoices: 300,
|
|
4341
|
+
MovedPermanently: 301,
|
|
4342
|
+
Found: 302,
|
|
4343
|
+
SeeOther: 303,
|
|
4344
|
+
NotModified: 304,
|
|
4345
|
+
UseProxy: 305,
|
|
4346
|
+
Unused: 306,
|
|
4347
|
+
TemporaryRedirect: 307,
|
|
4348
|
+
PermanentRedirect: 308,
|
|
4349
|
+
BadRequest: 400,
|
|
4350
|
+
Unauthorized: 401,
|
|
4351
|
+
PaymentRequired: 402,
|
|
4352
|
+
Forbidden: 403,
|
|
4353
|
+
NotFound: 404,
|
|
4354
|
+
MethodNotAllowed: 405,
|
|
4355
|
+
NotAcceptable: 406,
|
|
4356
|
+
ProxyAuthenticationRequired: 407,
|
|
4357
|
+
RequestTimeout: 408,
|
|
4358
|
+
Conflict: 409,
|
|
4359
|
+
Gone: 410,
|
|
4360
|
+
LengthRequired: 411,
|
|
4361
|
+
PreconditionFailed: 412,
|
|
4362
|
+
PayloadTooLarge: 413,
|
|
4363
|
+
UriTooLong: 414,
|
|
4364
|
+
UnsupportedMediaType: 415,
|
|
4365
|
+
RangeNotSatisfiable: 416,
|
|
4366
|
+
ExpectationFailed: 417,
|
|
4367
|
+
ImATeapot: 418,
|
|
4368
|
+
MisdirectedRequest: 421,
|
|
4369
|
+
UnprocessableEntity: 422,
|
|
4370
|
+
Locked: 423,
|
|
4371
|
+
FailedDependency: 424,
|
|
4372
|
+
TooEarly: 425,
|
|
4373
|
+
UpgradeRequired: 426,
|
|
4374
|
+
PreconditionRequired: 428,
|
|
4375
|
+
TooManyRequests: 429,
|
|
4376
|
+
RequestHeaderFieldsTooLarge: 431,
|
|
4377
|
+
UnavailableForLegalReasons: 451,
|
|
4378
|
+
InternalServerError: 500,
|
|
4379
|
+
NotImplemented: 501,
|
|
4380
|
+
BadGateway: 502,
|
|
4381
|
+
ServiceUnavailable: 503,
|
|
4382
|
+
GatewayTimeout: 504,
|
|
4383
|
+
HttpVersionNotSupported: 505,
|
|
4384
|
+
VariantAlsoNegotiates: 506,
|
|
4385
|
+
InsufficientStorage: 507,
|
|
4386
|
+
LoopDetected: 508,
|
|
4387
|
+
NotExtended: 510,
|
|
4388
|
+
NetworkAuthenticationRequired: 511,
|
|
4389
|
+
};
|
|
4390
|
+
|
|
4391
|
+
Object.entries(HttpStatusCode).forEach(([key, value]) => {
|
|
4392
|
+
HttpStatusCode[value] = key;
|
|
4393
|
+
});
|
|
4394
|
+
|
|
4242
4395
|
/**
|
|
4243
4396
|
* Create an instance of Axios
|
|
4244
4397
|
*
|
|
@@ -4247,11 +4400,11 @@ function isAxiosError(payload) {
|
|
|
4247
4400
|
* @returns {Axios} A new instance of Axios
|
|
4248
4401
|
*/
|
|
4249
4402
|
function createInstance(defaultConfig) {
|
|
4250
|
-
const context = new Axios
|
|
4251
|
-
const instance = bind(Axios
|
|
4403
|
+
const context = new Axios(defaultConfig);
|
|
4404
|
+
const instance = bind(Axios.prototype.request, context);
|
|
4252
4405
|
|
|
4253
4406
|
// Copy axios.prototype to instance
|
|
4254
|
-
utils$1.extend(instance, Axios
|
|
4407
|
+
utils$1.extend(instance, Axios.prototype, context, {allOwnKeys: true});
|
|
4255
4408
|
|
|
4256
4409
|
// Copy context to instance
|
|
4257
4410
|
utils$1.extend(instance, context, null, {allOwnKeys: true});
|
|
@@ -4265,14 +4418,14 @@ function createInstance(defaultConfig) {
|
|
|
4265
4418
|
}
|
|
4266
4419
|
|
|
4267
4420
|
// Create the default instance to be exported
|
|
4268
|
-
const req = createInstance(defaults
|
|
4421
|
+
const req = createInstance(defaults);
|
|
4269
4422
|
|
|
4270
4423
|
// Expose Axios class to allow class inheritance
|
|
4271
|
-
req.Axios = Axios
|
|
4424
|
+
req.Axios = Axios;
|
|
4272
4425
|
|
|
4273
4426
|
// Expose Cancel & CancelToken
|
|
4274
4427
|
req.CanceledError = CanceledError;
|
|
4275
|
-
req.CancelToken = CancelToken
|
|
4428
|
+
req.CancelToken = CancelToken;
|
|
4276
4429
|
req.isCancel = isCancel;
|
|
4277
4430
|
req.VERSION = VERSION;
|
|
4278
4431
|
req.toFormData = toFormData;
|
|
@@ -4294,7 +4447,7 @@ req.isAxiosError = isAxiosError;
|
|
|
4294
4447
|
// Expose mergeConfig
|
|
4295
4448
|
req.mergeConfig = mergeConfig;
|
|
4296
4449
|
|
|
4297
|
-
req.AxiosHeaders = AxiosHeaders
|
|
4450
|
+
req.AxiosHeaders = AxiosHeaders;
|
|
4298
4451
|
|
|
4299
4452
|
req.formToJSON = thing => formDataToJSON(utils$1.isHTMLForm(thing) ? new FormData(thing) : thing);
|
|
4300
4453
|
|