axios 1.7.5 → 1.7.7

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.7.5 Copyright (c) 2024 Matt Zabriskie and contributors
1
+ // Axios v1.7.7 Copyright (c) 2024 Matt Zabriskie and contributors
2
2
  'use strict';
3
3
 
4
4
  const FormData$1 = require('form-data');
@@ -2071,7 +2071,7 @@ function buildFullPath(baseURL, requestedURL) {
2071
2071
  return requestedURL;
2072
2072
  }
2073
2073
 
2074
- const VERSION = "1.7.5";
2074
+ const VERSION = "1.7.7";
2075
2075
 
2076
2076
  function parseProtocol(url) {
2077
2077
  const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
@@ -2963,7 +2963,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
2963
2963
  if (config.socketPath) {
2964
2964
  options.socketPath = config.socketPath;
2965
2965
  } else {
2966
- options.hostname = parsed.hostname;
2966
+ options.hostname = parsed.hostname.startsWith("[") ? parsed.hostname.slice(1, -1) : parsed.hostname;
2967
2967
  options.port = parsed.port;
2968
2968
  setProxy(options, config.proxy, protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path);
2969
2969
  }
@@ -3668,45 +3668,46 @@ const xhrAdapter = isXHRAdapterSupported && function (config) {
3668
3668
  };
3669
3669
 
3670
3670
  const composeSignals = (signals, timeout) => {
3671
- let controller = new AbortController();
3671
+ const {length} = (signals = signals ? signals.filter(Boolean) : []);
3672
3672
 
3673
- let aborted;
3673
+ if (timeout || length) {
3674
+ let controller = new AbortController();
3674
3675
 
3675
- const onabort = function (cancel) {
3676
- if (!aborted) {
3677
- aborted = true;
3678
- unsubscribe();
3679
- const err = cancel instanceof Error ? cancel : this.reason;
3680
- controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
3681
- }
3682
- };
3676
+ let aborted;
3683
3677
 
3684
- let timer = timeout && setTimeout(() => {
3685
- onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
3686
- }, timeout);
3678
+ const onabort = function (reason) {
3679
+ if (!aborted) {
3680
+ aborted = true;
3681
+ unsubscribe();
3682
+ const err = reason instanceof Error ? reason : this.reason;
3683
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
3684
+ }
3685
+ };
3687
3686
 
3688
- const unsubscribe = () => {
3689
- if (signals) {
3690
- timer && clearTimeout(timer);
3687
+ let timer = timeout && setTimeout(() => {
3691
3688
  timer = null;
3692
- signals.forEach(signal => {
3693
- signal &&
3694
- (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
3695
- });
3696
- signals = null;
3697
- }
3698
- };
3689
+ onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
3690
+ }, timeout);
3691
+
3692
+ const unsubscribe = () => {
3693
+ if (signals) {
3694
+ timer && clearTimeout(timer);
3695
+ timer = null;
3696
+ signals.forEach(signal => {
3697
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
3698
+ });
3699
+ signals = null;
3700
+ }
3701
+ };
3699
3702
 
3700
- signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
3703
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
3701
3704
 
3702
- const {signal} = controller;
3705
+ const {signal} = controller;
3703
3706
 
3704
- signal.unsubscribe = unsubscribe;
3707
+ signal.unsubscribe = () => utils$1.asap(unsubscribe);
3705
3708
 
3706
- return [signal, () => {
3707
- timer && clearTimeout(timer);
3708
- timer = null;
3709
- }];
3709
+ return signal;
3710
+ }
3710
3711
  };
3711
3712
 
3712
3713
  const composeSignals$1 = composeSignals;
@@ -3729,14 +3730,34 @@ const streamChunk = function* (chunk, chunkSize) {
3729
3730
  }
3730
3731
  };
3731
3732
 
3732
- const readBytes = async function* (iterable, chunkSize, encode) {
3733
- for await (const chunk of iterable) {
3734
- yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
3733
+ const readBytes = async function* (iterable, chunkSize) {
3734
+ for await (const chunk of readStream(iterable)) {
3735
+ yield* streamChunk(chunk, chunkSize);
3735
3736
  }
3736
3737
  };
3737
3738
 
3738
- const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
3739
- const iterator = readBytes(stream, chunkSize, encode);
3739
+ const readStream = async function* (stream) {
3740
+ if (stream[Symbol.asyncIterator]) {
3741
+ yield* stream;
3742
+ return;
3743
+ }
3744
+
3745
+ const reader = stream.getReader();
3746
+ try {
3747
+ for (;;) {
3748
+ const {done, value} = await reader.read();
3749
+ if (done) {
3750
+ break;
3751
+ }
3752
+ yield value;
3753
+ }
3754
+ } finally {
3755
+ await reader.cancel();
3756
+ }
3757
+ };
3758
+
3759
+ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
3760
+ const iterator = readBytes(stream, chunkSize);
3740
3761
 
3741
3762
  let bytes = 0;
3742
3763
  let done;
@@ -3839,7 +3860,11 @@ const getBodyLength = async (body) => {
3839
3860
  }
3840
3861
 
3841
3862
  if(utils$1.isSpecCompliantForm(body)) {
3842
- return (await new Request(body).arrayBuffer()).byteLength;
3863
+ const _request = new Request(platform.origin, {
3864
+ method: 'POST',
3865
+ body,
3866
+ });
3867
+ return (await _request.arrayBuffer()).byteLength;
3843
3868
  }
3844
3869
 
3845
3870
  if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
@@ -3879,18 +3904,13 @@ const fetchAdapter = isFetchSupported && (async (config) => {
3879
3904
 
3880
3905
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
3881
3906
 
3882
- let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
3883
- composeSignals$1([signal, cancelToken], timeout) : [];
3907
+ let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
3884
3908
 
3885
- let finished, request;
3909
+ let request;
3886
3910
 
3887
- const onFinish = () => {
3888
- !finished && setTimeout(() => {
3889
- composedSignal && composedSignal.unsubscribe();
3890
- });
3891
-
3892
- finished = true;
3893
- };
3911
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
3912
+ composedSignal.unsubscribe();
3913
+ });
3894
3914
 
3895
3915
  let requestContentLength;
3896
3916
 
@@ -3917,7 +3937,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
3917
3937
  progressEventReducer(asyncDecorator(onUploadProgress))
3918
3938
  );
3919
3939
 
3920
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
3940
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
3921
3941
  }
3922
3942
  }
3923
3943
 
@@ -3927,7 +3947,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
3927
3947
 
3928
3948
  // Cloudflare Workers throws when credentials are defined
3929
3949
  // see https://github.com/cloudflare/workerd/issues/902
3930
- const isCredentialsSupported = "credentials" in Request.prototype;
3950
+ const isCredentialsSupported = "credentials" in Request.prototype;
3931
3951
  request = new Request(url, {
3932
3952
  ...fetchOptions,
3933
3953
  signal: composedSignal,
@@ -3942,7 +3962,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
3942
3962
 
3943
3963
  const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
3944
3964
 
3945
- if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
3965
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
3946
3966
  const options = {};
3947
3967
 
3948
3968
  ['status', 'statusText', 'headers'].forEach(prop => {
@@ -3959,8 +3979,8 @@ const fetchAdapter = isFetchSupported && (async (config) => {
3959
3979
  response = new Response(
3960
3980
  trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
3961
3981
  flush && flush();
3962
- isStreamResponse && onFinish();
3963
- }, encodeText),
3982
+ unsubscribe && unsubscribe();
3983
+ }),
3964
3984
  options
3965
3985
  );
3966
3986
  }
@@ -3969,9 +3989,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
3969
3989
 
3970
3990
  let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
3971
3991
 
3972
- !isStreamResponse && onFinish();
3973
-
3974
- stopTimeout && stopTimeout();
3992
+ !isStreamResponse && unsubscribe && unsubscribe();
3975
3993
 
3976
3994
  return await new Promise((resolve, reject) => {
3977
3995
  settle(resolve, reject, {
@@ -3984,7 +4002,7 @@ const fetchAdapter = isFetchSupported && (async (config) => {
3984
4002
  });
3985
4003
  })
3986
4004
  } catch (err) {
3987
- onFinish();
4005
+ unsubscribe && unsubscribe();
3988
4006
 
3989
4007
  if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
3990
4008
  throw Object.assign(
@@ -4551,6 +4569,20 @@ class CancelToken {
4551
4569
  }
4552
4570
  }
4553
4571
 
4572
+ toAbortSignal() {
4573
+ const controller = new AbortController();
4574
+
4575
+ const abort = (err) => {
4576
+ controller.abort(err);
4577
+ };
4578
+
4579
+ this.subscribe(abort);
4580
+
4581
+ controller.signal.unsubscribe = () => this.unsubscribe(abort);
4582
+
4583
+ return controller.signal;
4584
+ }
4585
+
4554
4586
  /**
4555
4587
  * Returns an object that contains a new `CancelToken` and a function that, when called,
4556
4588
  * cancels the `CancelToken`.