axios 1.2.0 → 1.2.2

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.

Potentially problematic release.


This version of axios might be problematic. Click here for more details.

@@ -1,4 +1,4 @@
1
- // Axios v1.2.0 Copyright (c) 2022 Matt Zabriskie and contributors
1
+ // Axios v1.2.2 Copyright (c) 2022 Matt Zabriskie and contributors
2
2
  'use strict';
3
3
 
4
4
  const FormData$1 = require('form-data');
@@ -303,7 +303,11 @@ function findKey(obj, key) {
303
303
  return null;
304
304
  }
305
305
 
306
- const _global = typeof self === "undefined" ? typeof global === "undefined" ? undefined : global : self;
306
+ const _global = (() => {
307
+ /*eslint no-undef:0*/
308
+ if (typeof globalThis !== "undefined") return globalThis;
309
+ return typeof self !== "undefined" ? self : (typeof window !== 'undefined' ? window : global)
310
+ })();
307
311
 
308
312
  const isContextDefined = (context) => !isUndefined(context) && context !== _global;
309
313
 
@@ -1907,7 +1911,7 @@ function buildFullPath(baseURL, requestedURL) {
1907
1911
  return requestedURL;
1908
1912
  }
1909
1913
 
1910
- const VERSION = "1.2.0";
1914
+ const VERSION = "1.2.2";
1911
1915
 
1912
1916
  function parseProtocol(url) {
1913
1917
  const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
@@ -2040,7 +2044,7 @@ function speedometer(samplesCount, min) {
2040
2044
 
2041
2045
  const passed = startedAt && now - startedAt;
2042
2046
 
2043
- return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2047
+ return passed ? Math.round(bytesCount * 1000 / passed) : undefined;
2044
2048
  };
2045
2049
  }
2046
2050
 
@@ -2229,6 +2233,16 @@ class AxiosTransformStream extends stream__default["default"].Transform{
2229
2233
 
2230
2234
  const AxiosTransformStream$1 = AxiosTransformStream;
2231
2235
 
2236
+ const zlibOptions = {
2237
+ flush: zlib__default["default"].constants.Z_SYNC_FLUSH,
2238
+ finishFlush: zlib__default["default"].constants.Z_SYNC_FLUSH
2239
+ };
2240
+
2241
+ const brotliOptions = {
2242
+ flush: zlib__default["default"].constants.BROTLI_OPERATION_FLUSH,
2243
+ finishFlush: zlib__default["default"].constants.BROTLI_OPERATION_FLUSH
2244
+ };
2245
+
2232
2246
  const isBrotliSupported = utils.isFunction(zlib__default["default"].createBrotliDecompress);
2233
2247
 
2234
2248
  const {http: httpFollow, https: httpsFollow} = followRedirects__default["default"];
@@ -2469,7 +2483,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2469
2483
  }
2470
2484
  }
2471
2485
 
2472
- const contentLength = +headers.getContentLength();
2486
+ const contentLength = utils.toFiniteNumber(headers.getContentLength());
2473
2487
 
2474
2488
  if (utils.isArray(maxRate)) {
2475
2489
  maxUploadRate = maxRate[0];
@@ -2484,7 +2498,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2484
2498
  }
2485
2499
 
2486
2500
  data = stream__default["default"].pipeline([data, new AxiosTransformStream$1({
2487
- length: utils.toFiniteNumber(contentLength),
2501
+ length: contentLength,
2488
2502
  maxRate: utils.toFiniteNumber(maxUploadRate)
2489
2503
  })], utils.noop);
2490
2504
 
@@ -2527,7 +2541,10 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2527
2541
  return reject(customErr);
2528
2542
  }
2529
2543
 
2530
- headers.set('Accept-Encoding', 'gzip, deflate, br', false);
2544
+ headers.set(
2545
+ 'Accept-Encoding',
2546
+ 'gzip, compress, deflate' + (isBrotliSupported ? ', br' : ''), false
2547
+ );
2531
2548
 
2532
2549
  const options = {
2533
2550
  path,
@@ -2599,34 +2616,36 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2599
2616
  streams.push(transformStream);
2600
2617
  }
2601
2618
 
2602
- // uncompress the response body transparently if required
2619
+ // decompress the response body transparently if required
2603
2620
  let responseStream = res;
2604
2621
 
2605
2622
  // return the last request in case of redirects
2606
2623
  const lastRequest = res.req || req;
2607
2624
 
2608
2625
  // if decompress disabled we should not decompress
2609
- if (config.decompress !== false) {
2626
+ if (config.decompress !== false && res.headers['content-encoding']) {
2610
2627
  // if no content, but headers still say that it is encoded,
2611
2628
  // remove the header not confuse downstream operations
2612
- if ((!responseLength || res.statusCode === 204) && res.headers['content-encoding']) {
2629
+ if (method === 'HEAD' || res.statusCode === 204) {
2613
2630
  delete res.headers['content-encoding'];
2614
2631
  }
2615
2632
 
2616
2633
  switch (res.headers['content-encoding']) {
2617
2634
  /*eslint default-case:0*/
2618
2635
  case 'gzip':
2636
+ case 'x-gzip':
2619
2637
  case 'compress':
2638
+ case 'x-compress':
2620
2639
  case 'deflate':
2621
2640
  // add the unzipper to the body stream processing pipeline
2622
- streams.push(zlib__default["default"].createUnzip());
2641
+ streams.push(zlib__default["default"].createUnzip(zlibOptions));
2623
2642
 
2624
2643
  // remove the content-encoding in order to not confuse downstream operations
2625
2644
  delete res.headers['content-encoding'];
2626
2645
  break;
2627
2646
  case 'br':
2628
2647
  if (isBrotliSupported) {
2629
- streams.push(zlib__default["default"].createBrotliDecompress());
2648
+ streams.push(zlib__default["default"].createBrotliDecompress(brotliOptions));
2630
2649
  delete res.headers['content-encoding'];
2631
2650
  }
2632
2651
  }
@@ -2955,7 +2974,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2955
2974
  }
2956
2975
  }
2957
2976
 
2958
- if (utils.isFormData(requestData) && platform.isStandardBrowserEnv) {
2977
+ if (utils.isFormData(requestData) && (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv)) {
2959
2978
  requestHeaders.setContentType(false); // Let the browser set it
2960
2979
  }
2961
2980
 
@@ -2983,7 +3002,7 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
2983
3002
  const responseHeaders = AxiosHeaders$1.from(
2984
3003
  'getAllResponseHeaders' in request && request.getAllResponseHeaders()
2985
3004
  );
2986
- const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
3005
+ const responseData = !responseType || responseType === 'text' || responseType === 'json' ?
2987
3006
  request.responseText : request.response;
2988
3007
  const response = {
2989
3008
  data: responseData,
@@ -3210,7 +3229,7 @@ function throwIfCancellationRequested(config) {
3210
3229
  }
3211
3230
 
3212
3231
  if (config.signal && config.signal.aborted) {
3213
- throw new CanceledError();
3232
+ throw new CanceledError(null, config);
3214
3233
  }
3215
3234
  }
3216
3235
 
@@ -3801,6 +3820,78 @@ function isAxiosError(payload) {
3801
3820
  return utils.isObject(payload) && (payload.isAxiosError === true);
3802
3821
  }
3803
3822
 
3823
+ const HttpStatusCode = {
3824
+ Continue: 100,
3825
+ SwitchingProtocols: 101,
3826
+ Processing: 102,
3827
+ EarlyHints: 103,
3828
+ Ok: 200,
3829
+ Created: 201,
3830
+ Accepted: 202,
3831
+ NonAuthoritativeInformation: 203,
3832
+ NoContent: 204,
3833
+ ResetContent: 205,
3834
+ PartialContent: 206,
3835
+ MultiStatus: 207,
3836
+ AlreadyReported: 208,
3837
+ ImUsed: 226,
3838
+ MultipleChoices: 300,
3839
+ MovedPermanently: 301,
3840
+ Found: 302,
3841
+ SeeOther: 303,
3842
+ NotModified: 304,
3843
+ UseProxy: 305,
3844
+ Unused: 306,
3845
+ TemporaryRedirect: 307,
3846
+ PermanentRedirect: 308,
3847
+ BadRequest: 400,
3848
+ Unauthorized: 401,
3849
+ PaymentRequired: 402,
3850
+ Forbidden: 403,
3851
+ NotFound: 404,
3852
+ MethodNotAllowed: 405,
3853
+ NotAcceptable: 406,
3854
+ ProxyAuthenticationRequired: 407,
3855
+ RequestTimeout: 408,
3856
+ Conflict: 409,
3857
+ Gone: 410,
3858
+ LengthRequired: 411,
3859
+ PreconditionFailed: 412,
3860
+ PayloadTooLarge: 413,
3861
+ UriTooLong: 414,
3862
+ UnsupportedMediaType: 415,
3863
+ RangeNotSatisfiable: 416,
3864
+ ExpectationFailed: 417,
3865
+ ImATeapot: 418,
3866
+ MisdirectedRequest: 421,
3867
+ UnprocessableEntity: 422,
3868
+ Locked: 423,
3869
+ FailedDependency: 424,
3870
+ TooEarly: 425,
3871
+ UpgradeRequired: 426,
3872
+ PreconditionRequired: 428,
3873
+ TooManyRequests: 429,
3874
+ RequestHeaderFieldsTooLarge: 431,
3875
+ UnavailableForLegalReasons: 451,
3876
+ InternalServerError: 500,
3877
+ NotImplemented: 501,
3878
+ BadGateway: 502,
3879
+ ServiceUnavailable: 503,
3880
+ GatewayTimeout: 504,
3881
+ HttpVersionNotSupported: 505,
3882
+ VariantAlsoNegotiates: 506,
3883
+ InsufficientStorage: 507,
3884
+ LoopDetected: 508,
3885
+ NotExtended: 510,
3886
+ NetworkAuthenticationRequired: 511,
3887
+ };
3888
+
3889
+ Object.entries(HttpStatusCode).forEach(([key, value]) => {
3890
+ HttpStatusCode[value] = key;
3891
+ });
3892
+
3893
+ const HttpStatusCode$1 = HttpStatusCode;
3894
+
3804
3895
  /**
3805
3896
  * Create an instance of Axios
3806
3897
  *
@@ -3855,10 +3946,15 @@ axios.spread = spread;
3855
3946
  // Expose isAxiosError
3856
3947
  axios.isAxiosError = isAxiosError;
3857
3948
 
3949
+ // Expose mergeConfig
3950
+ axios.mergeConfig = mergeConfig;
3951
+
3858
3952
  axios.AxiosHeaders = AxiosHeaders$1;
3859
3953
 
3860
3954
  axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
3861
3955
 
3956
+ axios.HttpStatusCode = HttpStatusCode$1;
3957
+
3862
3958
  axios.default = axios;
3863
3959
 
3864
3960
  module.exports = axios;