@wiajs/req 1.7.12 → 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 CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @wia/req v1.7.12
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 Agent = require('@wiajs/agent');
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$1;
1989
+ const config = this || defaults;
1996
1990
  const context = response || config;
1997
- const headers = AxiosHeaders$1.from(context.headers);
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$1(value);
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,7 +2579,7 @@ const asyncDecorator =
2593
2579
  (...args) =>
2594
2580
  utils$1.asap(() => fn(...args));
2595
2581
 
2596
- 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)))}`});
2597
2583
 
2598
2584
  const isBrotliSupported = utils$1.isFunction(zlib.createBrotliDecompress);
2599
2585
 
@@ -2608,20 +2594,20 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils$1.kindOf(
2608
2594
  * 如需重新发起请求时,无需重新初始化
2609
2595
  */
2610
2596
  class HttpAdapter {
2611
- isDone = false;
2612
- rejected = false;
2597
+ isDone = false
2598
+ rejected = false
2613
2599
  /** @type {*} */
2614
- req = null;
2600
+ req = null
2615
2601
  /** @type {*} */
2616
- config = null;
2602
+ config = null
2617
2603
  /** @type {number} */
2618
- maxUploadRate;
2604
+ maxUploadRate
2619
2605
  /** @type {number} */
2620
- maxDownloadRate;
2606
+ maxDownloadRate
2621
2607
  /** @type {*} */
2622
- data = null;
2608
+ data = null
2623
2609
  /** @type {*} */
2624
- transport = null;
2610
+ transport = null
2625
2611
 
2626
2612
  /**
2627
2613
  *
@@ -2647,7 +2633,7 @@ class HttpAdapter {
2647
2633
  code === 204 ||
2648
2634
  // Not Modified
2649
2635
  code === 304
2650
- );
2636
+ )
2651
2637
  }
2652
2638
 
2653
2639
  /**
@@ -2655,7 +2641,10 @@ class HttpAdapter {
2655
2641
  * @param {*} reason
2656
2642
  */
2657
2643
  abort(reason) {
2658
- this.emitter.emit('abort', !reason || reason.type ? new CanceledError(null, this.config, this.req) : reason);
2644
+ this.emitter.emit(
2645
+ 'abort',
2646
+ !reason || reason.type ? new CanceledError(null, this.config, this.req) : reason
2647
+ );
2659
2648
  }
2660
2649
 
2661
2650
  onFinished() {
@@ -2687,7 +2676,7 @@ class HttpAdapter {
2687
2676
  * @returns
2688
2677
  */
2689
2678
  done(value, isRejected) {
2690
- if (this.isDone) return;
2679
+ if (this.isDone) return
2691
2680
  this.isDone = true;
2692
2681
  this?.onDone(value, isRejected);
2693
2682
  }
@@ -2706,7 +2695,10 @@ class HttpAdapter {
2706
2695
  _.method = method;
2707
2696
 
2708
2697
  if (lookup) {
2709
- const _lookup = callbackify$1(lookup, /** @param {*} value */ value => (utils$1.isArray(value) ? value : [value]));
2698
+ const _lookup = callbackify(
2699
+ lookup,
2700
+ /** @param {*} value */ value => (utils$1.isArray(value) ? value : [value])
2701
+ );
2710
2702
  // hotfix to support opt.all option which is required for node 20.x
2711
2703
  /**
2712
2704
  * @param {string} hostname
@@ -2715,7 +2707,7 @@ class HttpAdapter {
2715
2707
  */
2716
2708
  lookup = (hostname, opt, cb) => {
2717
2709
  _lookup(hostname, opt, (err, arg0, arg1) => {
2718
- if (err) return cb(err);
2710
+ if (err) return cb(err)
2719
2711
 
2720
2712
  const addresses = utils$1.isArray(arg0)
2721
2713
  ? arg0.map(addr => buildAddressEntry(addr))
@@ -2753,18 +2745,20 @@ class HttpAdapter {
2753
2745
 
2754
2746
  throw new AxiosError(
2755
2747
  `Request failed with status code ${response.status}`,
2756
- [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][Math.floor(response.status / 100) - 4],
2748
+ [AxiosError.ERR_BAD_REQUEST, AxiosError.ERR_BAD_RESPONSE][
2749
+ Math.floor(response.status / 100) - 4
2750
+ ],
2757
2751
  response.config,
2758
2752
  response.request,
2759
2753
  response
2760
- );
2754
+ )
2761
2755
  }
2762
2756
 
2763
2757
  if (supportedProtocols.indexOf(protocol) === -1) {
2764
- throw new AxiosError(`Unsupported protocol ${protocol}`, AxiosError.ERR_BAD_REQUEST, config);
2758
+ throw new AxiosError(`Unsupported protocol ${protocol}`, AxiosError.ERR_BAD_REQUEST, config)
2765
2759
  }
2766
2760
 
2767
- const headers = AxiosHeaders$1.from(config.headers).normalize();
2761
+ const headers = AxiosHeaders.from(config.headers).normalize();
2768
2762
 
2769
2763
  // Set User-Agent (required by some servers)
2770
2764
  // See https://github.com/axios/axios/issues/69
@@ -2783,10 +2777,14 @@ class HttpAdapter {
2783
2777
  if (utils$1.isSpecCompliantForm(data)) {
2784
2778
  const userBoundary = headers.getContentType(/boundary=([-_\w\d]{10,70})/i);
2785
2779
 
2786
- data = formDataToStream$1(data, /** @param {*} formHeaders */ formHeaders => headers.set(formHeaders), {
2787
- tag: `axios-${VERSION}-boundary`,
2788
- boundary: userBoundary?.[1] || undefined,
2789
- });
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
+ );
2790
2788
  // support for https://www.npmjs.com/package/form-data api
2791
2789
  } else if (utils$1.isFormData(data) && utils$1.isFunction(data.getHeaders)) {
2792
2790
  headers.set(data.getHeaders());
@@ -2800,7 +2798,7 @@ class HttpAdapter {
2800
2798
  } else if (utils$1.isBlob(data)) {
2801
2799
  data.size && headers.setContentType(data.type || 'application/octet-stream');
2802
2800
  headers.setContentLength(data.size || 0);
2803
- data = stream$1.Readable.from(readBlob$1(data));
2801
+ data = stream$1.Readable.from(readBlob(data));
2804
2802
  } else if (data && !utils$1.isStream(data)) {
2805
2803
  if (Buffer.isBuffer(data)) ; else if (utils$1.isArrayBuffer(data)) {
2806
2804
  data = Buffer.from(new Uint8Array(data));
@@ -2811,14 +2809,18 @@ class HttpAdapter {
2811
2809
  'Data after transformation must be a string, an ArrayBuffer, a Buffer, or a Stream',
2812
2810
  AxiosError.ERR_BAD_REQUEST,
2813
2811
  config
2814
- );
2812
+ )
2815
2813
  }
2816
2814
 
2817
2815
  // Add Content-Length header if data exists
2818
2816
  headers.setContentLength(data.length, false);
2819
2817
 
2820
2818
  if (config.maxBodyLength > -1 && data.length > config.maxBodyLength) {
2821
- throw new AxiosError('Request body larger than maxBodyLength limit', AxiosError.ERR_BAD_REQUEST, config);
2819
+ throw new AxiosError(
2820
+ 'Request body larger than maxBodyLength limit',
2821
+ AxiosError.ERR_BAD_REQUEST,
2822
+ config
2823
+ )
2822
2824
  }
2823
2825
  }
2824
2826
 
@@ -2842,7 +2844,7 @@ class HttpAdapter {
2842
2844
  data = stream$1.pipeline(
2843
2845
  [
2844
2846
  data,
2845
- new AxiosTransformStream$1({
2847
+ new AxiosTransformStream({
2846
2848
  maxRate: utils$1.toFiniteNumber(maxUploadRate),
2847
2849
  }),
2848
2850
  ],
@@ -2854,7 +2856,10 @@ class HttpAdapter {
2854
2856
  'progress',
2855
2857
  flushOnFinish(
2856
2858
  data,
2857
- progressEventDecorator(contentLength, progressEventReducer(asyncDecorator(onUploadProgress), false, 3))
2859
+ progressEventDecorator(
2860
+ contentLength,
2861
+ progressEventReducer(asyncDecorator(onUploadProgress), false, 3)
2862
+ )
2858
2863
  )
2859
2864
  );
2860
2865
  }
@@ -2878,29 +2883,40 @@ class HttpAdapter {
2878
2883
  let path;
2879
2884
 
2880
2885
  try {
2881
- path = buildURL(parsed.pathname + parsed.search, config.params, config.paramsSerializer).replace(/^\?/, '');
2886
+ path = buildURL(
2887
+ parsed.pathname + parsed.search,
2888
+ config.params,
2889
+ config.paramsSerializer
2890
+ ).replace(/^\?/, '');
2882
2891
  } catch (err) {
2883
2892
  /** @type {*} */
2884
2893
  const customErr = new Error(err.message);
2885
2894
  customErr.config = config;
2886
2895
  customErr.url = config.url;
2887
2896
  customErr.exists = true;
2888
- throw customErr;
2897
+ throw customErr
2889
2898
  }
2890
2899
 
2891
- headers.set('Accept-Encoding', `gzip, compress, deflate${isBrotliSupported ? ', br' : ''}`, false);
2900
+ headers.set(
2901
+ 'Accept-Encoding',
2902
+ `gzip, compress, deflate${isBrotliSupported ? ', br' : ''}`,
2903
+ false
2904
+ );
2892
2905
 
2893
2906
  /** @type {*} */
2894
2907
  const options = {
2895
2908
  path,
2896
2909
  method,
2897
2910
  headers: headers.toJSON(),
2898
- agents: {http: config.httpAgent, https: config.httpsAgent},
2911
+ // agents: {http: config.httpAgent, https: config.httpsAgent},
2912
+ agents,
2899
2913
  auth,
2900
2914
  protocol,
2901
2915
  family,
2902
2916
  beforeRedirect: dispatchBeforeRedirect,
2903
2917
  beforeRedirects: {},
2918
+ http,
2919
+ https,
2904
2920
  };
2905
2921
 
2906
2922
  // cacheable-lookup integration hotfix
@@ -2908,16 +2924,19 @@ class HttpAdapter {
2908
2924
 
2909
2925
  if (config.socketPath) options.socketPath = config.socketPath;
2910
2926
  else {
2911
- options.hostname = parsed.hostname.startsWith('[') ? parsed.hostname.slice(1, -1) : parsed.hostname;
2927
+ options.hostname = parsed.hostname.startsWith('[')
2928
+ ? parsed.hostname.slice(1, -1)
2929
+ : parsed.hostname;
2912
2930
  options.port = parsed.port;
2913
2931
  // ! proxy 配置了 agent,否则使用缺省 agent
2914
- if (config.agent) options.agents = new Agent(config.agent);
2932
+ if (config.agent) options.agents = new agent.Agent(config.agent);
2915
2933
  }
2916
2934
 
2917
2935
  // 执行请求的具体对象
2918
2936
  _.transport = config.transport;
2919
2937
 
2920
2938
  const isHttpsRequest = isHttps.test(options.protocol);
2939
+ // agents 优先于 agent,在 request中根据协议从 agents 中获取
2921
2940
  options.agent = isHttpsRequest ? config.httpsAgent : config.httpAgent;
2922
2941
 
2923
2942
  if (config.maxBodyLength > -1) options.maxBodyLength = config.maxBodyLength;
@@ -2938,7 +2957,7 @@ class HttpAdapter {
2938
2957
  _.data = data;
2939
2958
 
2940
2959
  log({config}, 'init');
2941
- return options;
2960
+ return options
2942
2961
  }
2943
2962
 
2944
2963
  /**
@@ -2968,7 +2987,7 @@ class HttpAdapter {
2968
2987
  Blob: config.env?.Blob,
2969
2988
  });
2970
2989
  } catch (err) {
2971
- throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config);
2990
+ throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config)
2972
2991
  }
2973
2992
 
2974
2993
  if (responseType === 'text') {
@@ -2986,13 +3005,13 @@ class HttpAdapter {
2986
3005
  data: convertedData,
2987
3006
  status: 200,
2988
3007
  statusText: 'OK',
2989
- headers: new AxiosHeaders$1(),
3008
+ headers: new AxiosHeaders(),
2990
3009
  config,
2991
3010
  };
2992
3011
  } else {
2993
3012
  let transformStream;
2994
3013
  if (onDownloadProgress || maxDownloadRate) {
2995
- transformStream = new AxiosTransformStream$1({
3014
+ transformStream = new AxiosTransformStream({
2996
3015
  maxRate: utils$1.toFiniteNumber(maxDownloadRate),
2997
3016
  });
2998
3017
 
@@ -3020,7 +3039,8 @@ class HttpAdapter {
3020
3039
  // log.debug('request', {options});
3021
3040
  const req = transport ? transport.request(options) : request(options);
3022
3041
 
3023
- if (!req) return reject(new AxiosError('Request failed.', AxiosError.ERR_BAD_REQUEST, config));
3042
+ if (!req)
3043
+ return reject(new AxiosError('Request failed.', AxiosError.ERR_BAD_REQUEST, config))
3024
3044
 
3025
3045
  _.req = req;
3026
3046
 
@@ -3072,7 +3092,7 @@ class HttpAdapter {
3072
3092
  // And then these socket which be hang up will devouring CPU little by little.
3073
3093
  // ClientRequest.setTimeout will be fired on the specify milliseconds, and can make sure that abort() will be fired after connect.
3074
3094
  req.setTimeout(timeout, () => {
3075
- if (_.isDone) return;
3095
+ if (_.isDone) return
3076
3096
 
3077
3097
  let timeoutErrorMessage = config.timeout
3078
3098
  ? `timeout of ${config.timeout}ms exceeded`
@@ -3084,7 +3104,9 @@ class HttpAdapter {
3084
3104
  reject(
3085
3105
  new AxiosError(
3086
3106
  timeoutErrorMessage,
3087
- transitional.clarifyTimeoutError ? AxiosError.ETIMEDOUT : AxiosError.ECONNABORTED,
3107
+ transitional.clarifyTimeoutError
3108
+ ? AxiosError.ETIMEDOUT
3109
+ : AxiosError.ECONNABORTED,
3088
3110
  config,
3089
3111
  req
3090
3112
  )
@@ -3108,7 +3130,7 @@ class HttpAdapter {
3108
3130
  * @param {*} stream
3109
3131
  */
3110
3132
  (res, stream) => {
3111
- if (req.destroyed) return;
3133
+ if (req.destroyed) return
3112
3134
 
3113
3135
  // 'transfer-encoding': 'chunked'时,无content-length,axios v1.2 不能自动解压
3114
3136
  const responseLength = +res.headers['content-length'];
@@ -3126,7 +3148,7 @@ class HttpAdapter {
3126
3148
  const response = {
3127
3149
  status: res.statusCode,
3128
3150
  statusText: res.statusMessage,
3129
- headers: new AxiosHeaders$1(res.headers),
3151
+ headers: new AxiosHeaders(res.headers),
3130
3152
  config,
3131
3153
  request: lastRequest,
3132
3154
  };
@@ -3149,7 +3171,10 @@ class HttpAdapter {
3149
3171
  totalResponseBytes += chunk.length;
3150
3172
 
3151
3173
  // make sure the content length is not over the maxContentLength if specified
3152
- if (config.maxContentLength > -1 && totalResponseBytes > config.maxContentLength) {
3174
+ if (
3175
+ config.maxContentLength > -1 &&
3176
+ totalResponseBytes > config.maxContentLength
3177
+ ) {
3153
3178
  // stream.destroy() emit aborted event before calling reject() on Node.js v16
3154
3179
  _.rejected = true;
3155
3180
  stream.destroy();
@@ -3166,7 +3191,7 @@ class HttpAdapter {
3166
3191
  );
3167
3192
 
3168
3193
  stream.on('aborted', function handlerStreamAborted() {
3169
- if (_.rejected) return;
3194
+ if (_.rejected) return
3170
3195
 
3171
3196
  const err = new AxiosError(
3172
3197
  `maxContentLength size of ${config.maxContentLength} exceeded`,
@@ -3179,7 +3204,7 @@ class HttpAdapter {
3179
3204
  });
3180
3205
 
3181
3206
  stream.on('error', function handleStreamError(err) {
3182
- if (req.destroyed) return;
3207
+ if (req.destroyed) return
3183
3208
  reject(AxiosError.from(err, null, config, lastRequest));
3184
3209
  });
3185
3210
 
@@ -3187,7 +3212,9 @@ class HttpAdapter {
3187
3212
  stream.on('end', function handleStreamEnd() {
3188
3213
  try {
3189
3214
  let responseData =
3190
- responseBuffer.length === 1 ? responseBuffer[0] : Buffer.concat(responseBuffer);
3215
+ responseBuffer.length === 1
3216
+ ? responseBuffer[0]
3217
+ : Buffer.concat(responseBuffer);
3191
3218
  if (responseType !== 'arraybuffer') {
3192
3219
  responseData = responseData.toString(responseEncoding);
3193
3220
  if (!responseEncoding || responseEncoding === 'utf8') {
@@ -3245,13 +3272,12 @@ class HttpAdapter {
3245
3272
  } catch (e) {
3246
3273
  log.error(e, 'request');
3247
3274
  _.done(e, true);
3248
- throw e;
3275
+ throw e
3249
3276
  }
3250
- return R;
3277
+ return R
3251
3278
  }
3252
3279
  }
3253
3280
 
3254
-
3255
3281
  /**
3256
3282
  *
3257
3283
  * @param {*} stream
@@ -3261,7 +3287,7 @@ class HttpAdapter {
3261
3287
  const flushOnFinish = (stream, [throttled, flush]) => {
3262
3288
  stream.on('end', flush).on('error', flush);
3263
3289
 
3264
- return throttled;
3290
+ return throttled
3265
3291
  };
3266
3292
 
3267
3293
  /** @typedef {import('../core/Axios').default} Axios */
@@ -3288,13 +3314,13 @@ function dispatchBeforeRedirect(options, responseDetails) {
3288
3314
  */
3289
3315
  function resolveFamily({address, family}) {
3290
3316
  if (!utils$1.isString(address)) {
3291
- throw TypeError('address must be a string');
3317
+ throw TypeError('address must be a string')
3292
3318
  }
3293
3319
 
3294
3320
  return {
3295
3321
  address,
3296
3322
  family: family || (address.indexOf('.') < 0 ? 6 : 4),
3297
- };
3323
+ }
3298
3324
  }
3299
3325
 
3300
3326
  /**
@@ -3311,6 +3337,69 @@ function buildAddressEntry(address, family) {
3311
3337
  */
3312
3338
  const HttpAdapter$1 = isHttpAdapterSupported && HttpAdapter;
3313
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
+
3314
3403
  const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
3315
3404
  class XhrAdapter {
3316
3405
  constructor(config) {
@@ -3423,7 +3512,7 @@ function dispatchRequest(config) {
3423
3512
  let R;
3424
3513
  throwIfCancellationRequested(config);
3425
3514
 
3426
- config.headers = AxiosHeaders$1.from(config.headers);
3515
+ config.headers = AxiosHeaders.from(config.headers);
3427
3516
 
3428
3517
  // Transform request data
3429
3518
  config.data = transformData.call(config, config.transformRequest);
@@ -3432,7 +3521,7 @@ function dispatchRequest(config) {
3432
3521
  config.headers.setContentType('application/x-www-form-urlencoded', false);
3433
3522
  }
3434
3523
 
3435
- const Adapter = adapters.getAdapter(config.adapter || defaults$1.adapter);
3524
+ const Adapter = adapters.getAdapter(config.adapter || defaults.adapter);
3436
3525
  const adapter = new Adapter(config);
3437
3526
 
3438
3527
  if (config.stream) R = adapter.request(this);
@@ -3451,7 +3540,7 @@ function dispatchRequest(config) {
3451
3540
  });
3452
3541
  // if (response.data && !response.body) response.body = response.data
3453
3542
 
3454
- response.headers = AxiosHeaders$1.from(response.headers);
3543
+ response.headers = AxiosHeaders.from(response.headers);
3455
3544
 
3456
3545
  return response
3457
3546
  },
@@ -3464,7 +3553,7 @@ function dispatchRequest(config) {
3464
3553
  reason.response.data = transformData.call(config, config.transformResponse, reason.response);
3465
3554
  // body === data
3466
3555
  if (reason.response.data && !reason.response.body) reason.response.body = reason.response.data;
3467
- reason.response.headers = AxiosHeaders$1.from(reason.response.headers);
3556
+ reason.response.headers = AxiosHeaders.from(reason.response.headers);
3468
3557
  }
3469
3558
  }
3470
3559
 
@@ -3475,7 +3564,7 @@ function dispatchRequest(config) {
3475
3564
  return R
3476
3565
  }
3477
3566
 
3478
- const headersToObject = (thing) => thing instanceof AxiosHeaders$1 ? { ...thing } : thing;
3567
+ const headersToObject = (thing) => thing instanceof AxiosHeaders ? { ...thing } : thing;
3479
3568
 
3480
3569
  /**
3481
3570
  * Config-specific merge-function which creates a new config-object
@@ -3686,8 +3775,8 @@ class Axios {
3686
3775
  this.defaults = instanceConfig;
3687
3776
  this.config = this.defaults; // !+++
3688
3777
  this.interceptors = {
3689
- request: new InterceptorManager$1(),
3690
- response: new InterceptorManager$1(),
3778
+ request: new InterceptorManager(),
3779
+ response: new InterceptorManager(),
3691
3780
  };
3692
3781
 
3693
3782
  this.init(); // !+++
@@ -3874,7 +3963,7 @@ class Axios {
3874
3963
  });
3875
3964
 
3876
3965
  // 源值存在,则不覆盖,contextHeaders 优先于 headers
3877
- config.headers = AxiosHeaders$1.concat(contextHeaders, headers);
3966
+ config.headers = AxiosHeaders.concat(contextHeaders, headers);
3878
3967
 
3879
3968
  // filter out skipped interceptors
3880
3969
  const requestInterceptorChain = []; // 请求拦截器,hook
@@ -4063,9 +4152,7 @@ utils$1.forEach(['posts', 'puts', 'patchs'], function forEachMethodWithData(meth
4063
4152
  Axios.prototype[method] = generateStreamMethod();
4064
4153
 
4065
4154
  Axios.prototype[`${method}Forms`] = generateStreamMethod(true);
4066
- });
4067
-
4068
- const Axios$1 = Axios;
4155
+ });
4069
4156
 
4070
4157
  /**
4071
4158
  * A `CancelToken` is an object that can be used to request cancellation of an operation.
@@ -4195,9 +4282,7 @@ class CancelToken {
4195
4282
  cancel
4196
4283
  };
4197
4284
  }
4198
- }
4199
-
4200
- const CancelToken$1 = CancelToken;
4285
+ }
4201
4286
 
4202
4287
  /**
4203
4288
  * Syntactic sugar for invoking a function and expanding an array for arguments.
@@ -4237,6 +4322,76 @@ function isAxiosError(payload) {
4237
4322
  return utils$1.isObject(payload) && (payload.isAxiosError === true);
4238
4323
  }
4239
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
+
4240
4395
  /**
4241
4396
  * Create an instance of Axios
4242
4397
  *
@@ -4245,11 +4400,11 @@ function isAxiosError(payload) {
4245
4400
  * @returns {Axios} A new instance of Axios
4246
4401
  */
4247
4402
  function createInstance(defaultConfig) {
4248
- const context = new Axios$1(defaultConfig);
4249
- const instance = bind(Axios$1.prototype.request, context);
4403
+ const context = new Axios(defaultConfig);
4404
+ const instance = bind(Axios.prototype.request, context);
4250
4405
 
4251
4406
  // Copy axios.prototype to instance
4252
- utils$1.extend(instance, Axios$1.prototype, context, {allOwnKeys: true});
4407
+ utils$1.extend(instance, Axios.prototype, context, {allOwnKeys: true});
4253
4408
 
4254
4409
  // Copy context to instance
4255
4410
  utils$1.extend(instance, context, null, {allOwnKeys: true});
@@ -4263,14 +4418,14 @@ function createInstance(defaultConfig) {
4263
4418
  }
4264
4419
 
4265
4420
  // Create the default instance to be exported
4266
- const req = createInstance(defaults$1);
4421
+ const req = createInstance(defaults);
4267
4422
 
4268
4423
  // Expose Axios class to allow class inheritance
4269
- req.Axios = Axios$1;
4424
+ req.Axios = Axios;
4270
4425
 
4271
4426
  // Expose Cancel & CancelToken
4272
4427
  req.CanceledError = CanceledError;
4273
- req.CancelToken = CancelToken$1;
4428
+ req.CancelToken = CancelToken;
4274
4429
  req.isCancel = isCancel;
4275
4430
  req.VERSION = VERSION;
4276
4431
  req.toFormData = toFormData;
@@ -4292,7 +4447,7 @@ req.isAxiosError = isAxiosError;
4292
4447
  // Expose mergeConfig
4293
4448
  req.mergeConfig = mergeConfig;
4294
4449
 
4295
- req.AxiosHeaders = AxiosHeaders$1;
4450
+ req.AxiosHeaders = AxiosHeaders;
4296
4451
 
4297
4452
  req.formToJSON = thing => formDataToJSON(utils$1.isHTMLForm(thing) ? new FormData(thing) : thing);
4298
4453