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
  function bind(fn, thisArg) {
@@ -2637,45 +2637,46 @@ var xhrAdapter = isXHRAdapterSupported && function (config) {
2637
2637
  };
2638
2638
 
2639
2639
  const composeSignals = (signals, timeout) => {
2640
- let controller = new AbortController();
2640
+ const {length} = (signals = signals ? signals.filter(Boolean) : []);
2641
2641
 
2642
- let aborted;
2642
+ if (timeout || length) {
2643
+ let controller = new AbortController();
2643
2644
 
2644
- const onabort = function (cancel) {
2645
- if (!aborted) {
2646
- aborted = true;
2647
- unsubscribe();
2648
- const err = cancel instanceof Error ? cancel : this.reason;
2649
- controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
2650
- }
2651
- };
2645
+ let aborted;
2652
2646
 
2653
- let timer = timeout && setTimeout(() => {
2654
- onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
2655
- }, timeout);
2647
+ const onabort = function (reason) {
2648
+ if (!aborted) {
2649
+ aborted = true;
2650
+ unsubscribe();
2651
+ const err = reason instanceof Error ? reason : this.reason;
2652
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
2653
+ }
2654
+ };
2656
2655
 
2657
- const unsubscribe = () => {
2658
- if (signals) {
2659
- timer && clearTimeout(timer);
2656
+ let timer = timeout && setTimeout(() => {
2660
2657
  timer = null;
2661
- signals.forEach(signal => {
2662
- signal &&
2663
- (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
2664
- });
2665
- signals = null;
2666
- }
2667
- };
2658
+ onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT));
2659
+ }, timeout);
2660
+
2661
+ const unsubscribe = () => {
2662
+ if (signals) {
2663
+ timer && clearTimeout(timer);
2664
+ timer = null;
2665
+ signals.forEach(signal => {
2666
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
2667
+ });
2668
+ signals = null;
2669
+ }
2670
+ };
2668
2671
 
2669
- signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
2672
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
2670
2673
 
2671
- const {signal} = controller;
2674
+ const {signal} = controller;
2672
2675
 
2673
- signal.unsubscribe = unsubscribe;
2676
+ signal.unsubscribe = () => utils$1.asap(unsubscribe);
2674
2677
 
2675
- return [signal, () => {
2676
- timer && clearTimeout(timer);
2677
- timer = null;
2678
- }];
2678
+ return signal;
2679
+ }
2679
2680
  };
2680
2681
 
2681
2682
  var composeSignals$1 = composeSignals;
@@ -2698,14 +2699,34 @@ const streamChunk = function* (chunk, chunkSize) {
2698
2699
  }
2699
2700
  };
2700
2701
 
2701
- const readBytes = async function* (iterable, chunkSize, encode) {
2702
- for await (const chunk of iterable) {
2703
- yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
2702
+ const readBytes = async function* (iterable, chunkSize) {
2703
+ for await (const chunk of readStream(iterable)) {
2704
+ yield* streamChunk(chunk, chunkSize);
2705
+ }
2706
+ };
2707
+
2708
+ const readStream = async function* (stream) {
2709
+ if (stream[Symbol.asyncIterator]) {
2710
+ yield* stream;
2711
+ return;
2712
+ }
2713
+
2714
+ const reader = stream.getReader();
2715
+ try {
2716
+ for (;;) {
2717
+ const {done, value} = await reader.read();
2718
+ if (done) {
2719
+ break;
2720
+ }
2721
+ yield value;
2722
+ }
2723
+ } finally {
2724
+ await reader.cancel();
2704
2725
  }
2705
2726
  };
2706
2727
 
2707
- const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
2708
- const iterator = readBytes(stream, chunkSize, encode);
2728
+ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
2729
+ const iterator = readBytes(stream, chunkSize);
2709
2730
 
2710
2731
  let bytes = 0;
2711
2732
  let done;
@@ -2808,7 +2829,11 @@ const getBodyLength = async (body) => {
2808
2829
  }
2809
2830
 
2810
2831
  if(utils$1.isSpecCompliantForm(body)) {
2811
- return (await new Request(body).arrayBuffer()).byteLength;
2832
+ const _request = new Request(platform.origin, {
2833
+ method: 'POST',
2834
+ body,
2835
+ });
2836
+ return (await _request.arrayBuffer()).byteLength;
2812
2837
  }
2813
2838
 
2814
2839
  if(utils$1.isArrayBufferView(body) || utils$1.isArrayBuffer(body)) {
@@ -2848,18 +2873,13 @@ var fetchAdapter = isFetchSupported && (async (config) => {
2848
2873
 
2849
2874
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
2850
2875
 
2851
- let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
2852
- composeSignals$1([signal, cancelToken], timeout) : [];
2876
+ let composedSignal = composeSignals$1([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
2853
2877
 
2854
- let finished, request;
2878
+ let request;
2855
2879
 
2856
- const onFinish = () => {
2857
- !finished && setTimeout(() => {
2858
- composedSignal && composedSignal.unsubscribe();
2859
- });
2860
-
2861
- finished = true;
2862
- };
2880
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
2881
+ composedSignal.unsubscribe();
2882
+ });
2863
2883
 
2864
2884
  let requestContentLength;
2865
2885
 
@@ -2886,7 +2906,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
2886
2906
  progressEventReducer(asyncDecorator(onUploadProgress))
2887
2907
  );
2888
2908
 
2889
- data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
2909
+ data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
2890
2910
  }
2891
2911
  }
2892
2912
 
@@ -2896,7 +2916,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
2896
2916
 
2897
2917
  // Cloudflare Workers throws when credentials are defined
2898
2918
  // see https://github.com/cloudflare/workerd/issues/902
2899
- const isCredentialsSupported = "credentials" in Request.prototype;
2919
+ const isCredentialsSupported = "credentials" in Request.prototype;
2900
2920
  request = new Request(url, {
2901
2921
  ...fetchOptions,
2902
2922
  signal: composedSignal,
@@ -2911,7 +2931,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
2911
2931
 
2912
2932
  const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
2913
2933
 
2914
- if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
2934
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
2915
2935
  const options = {};
2916
2936
 
2917
2937
  ['status', 'statusText', 'headers'].forEach(prop => {
@@ -2928,8 +2948,8 @@ var fetchAdapter = isFetchSupported && (async (config) => {
2928
2948
  response = new Response(
2929
2949
  trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
2930
2950
  flush && flush();
2931
- isStreamResponse && onFinish();
2932
- }, encodeText),
2951
+ unsubscribe && unsubscribe();
2952
+ }),
2933
2953
  options
2934
2954
  );
2935
2955
  }
@@ -2938,9 +2958,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
2938
2958
 
2939
2959
  let responseData = await resolvers[utils$1.findKey(resolvers, responseType) || 'text'](response, config);
2940
2960
 
2941
- !isStreamResponse && onFinish();
2942
-
2943
- stopTimeout && stopTimeout();
2961
+ !isStreamResponse && unsubscribe && unsubscribe();
2944
2962
 
2945
2963
  return await new Promise((resolve, reject) => {
2946
2964
  settle(resolve, reject, {
@@ -2953,7 +2971,7 @@ var fetchAdapter = isFetchSupported && (async (config) => {
2953
2971
  });
2954
2972
  })
2955
2973
  } catch (err) {
2956
- onFinish();
2974
+ unsubscribe && unsubscribe();
2957
2975
 
2958
2976
  if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
2959
2977
  throw Object.assign(
@@ -3115,7 +3133,7 @@ function dispatchRequest(config) {
3115
3133
  });
3116
3134
  }
3117
3135
 
3118
- const VERSION = "1.7.5";
3136
+ const VERSION = "1.7.7";
3119
3137
 
3120
3138
  const validators$1 = {};
3121
3139
 
@@ -3522,6 +3540,20 @@ class CancelToken {
3522
3540
  }
3523
3541
  }
3524
3542
 
3543
+ toAbortSignal() {
3544
+ const controller = new AbortController();
3545
+
3546
+ const abort = (err) => {
3547
+ controller.abort(err);
3548
+ };
3549
+
3550
+ this.subscribe(abort);
3551
+
3552
+ controller.signal.unsubscribe = () => this.unsubscribe(abort);
3553
+
3554
+ return controller.signal;
3555
+ }
3556
+
3525
3557
  /**
3526
3558
  * Returns an object that contains a new `CancelToken` and a function that, when called,
3527
3559
  * cancels the `CancelToken`.