axios 1.7.5 → 1.7.6

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.

@@ -69,7 +69,11 @@ const getBodyLength = async (body) => {
69
69
  }
70
70
 
71
71
  if(utils.isSpecCompliantForm(body)) {
72
- return (await new Request(body).arrayBuffer()).byteLength;
72
+ const _request = new Request(platform.origin, {
73
+ method: 'POST',
74
+ body,
75
+ });
76
+ return (await _request.arrayBuffer()).byteLength;
73
77
  }
74
78
 
75
79
  if(utils.isArrayBufferView(body) || utils.isArrayBuffer(body)) {
@@ -109,18 +113,13 @@ export default isFetchSupported && (async (config) => {
109
113
 
110
114
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
111
115
 
112
- let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
113
- composeSignals([signal, cancelToken], timeout) : [];
114
-
115
- let finished, request;
116
+ let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
116
117
 
117
- const onFinish = () => {
118
- !finished && setTimeout(() => {
119
- composedSignal && composedSignal.unsubscribe();
120
- });
118
+ let request;
121
119
 
122
- finished = true;
123
- }
120
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
121
+ composedSignal.unsubscribe();
122
+ });
124
123
 
125
124
  let requestContentLength;
126
125
 
@@ -157,7 +156,7 @@ export default isFetchSupported && (async (config) => {
157
156
 
158
157
  // Cloudflare Workers throws when credentials are defined
159
158
  // see https://github.com/cloudflare/workerd/issues/902
160
- const isCredentialsSupported = "credentials" in Request.prototype;
159
+ const isCredentialsSupported = "credentials" in Request.prototype;
161
160
  request = new Request(url, {
162
161
  ...fetchOptions,
163
162
  signal: composedSignal,
@@ -172,7 +171,7 @@ export default isFetchSupported && (async (config) => {
172
171
 
173
172
  const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
174
173
 
175
- if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
174
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
176
175
  const options = {};
177
176
 
178
177
  ['status', 'statusText', 'headers'].forEach(prop => {
@@ -189,7 +188,7 @@ export default isFetchSupported && (async (config) => {
189
188
  response = new Response(
190
189
  trackStream(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
191
190
  flush && flush();
192
- isStreamResponse && onFinish();
191
+ unsubscribe && unsubscribe();
193
192
  }, encodeText),
194
193
  options
195
194
  );
@@ -199,9 +198,7 @@ export default isFetchSupported && (async (config) => {
199
198
 
200
199
  let responseData = await resolvers[utils.findKey(resolvers, responseType) || 'text'](response, config);
201
200
 
202
- !isStreamResponse && onFinish();
203
-
204
- stopTimeout && stopTimeout();
201
+ !isStreamResponse && unsubscribe && unsubscribe();
205
202
 
206
203
  return await new Promise((resolve, reject) => {
207
204
  settle(resolve, reject, {
@@ -214,7 +211,7 @@ export default isFetchSupported && (async (config) => {
214
211
  })
215
212
  })
216
213
  } catch (err) {
217
- onFinish();
214
+ unsubscribe && unsubscribe();
218
215
 
219
216
  if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
220
217
  throw Object.assign(
@@ -102,6 +102,20 @@ class CancelToken {
102
102
  }
103
103
  }
104
104
 
105
+ toAbortSignal() {
106
+ const controller = new AbortController();
107
+
108
+ const abort = (err) => {
109
+ controller.abort(err);
110
+ };
111
+
112
+ this.subscribe(abort);
113
+
114
+ controller.signal.unsubscribe = () => this.unsubscribe(abort);
115
+
116
+ return controller.signal;
117
+ }
118
+
105
119
  /**
106
120
  * Returns an object that contains a new `CancelToken` and a function that, when called,
107
121
  * cancels the `CancelToken`.
package/lib/env/data.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "1.7.5";
1
+ export const VERSION = "1.7.6";
@@ -1,46 +1,48 @@
1
1
  import CanceledError from "../cancel/CanceledError.js";
2
2
  import AxiosError from "../core/AxiosError.js";
3
+ import utils from '../utils.js';
3
4
 
4
5
  const composeSignals = (signals, timeout) => {
5
- let controller = new AbortController();
6
+ const {length} = (signals = signals ? signals.filter(Boolean) : []);
6
7
 
7
- let aborted;
8
+ if (timeout || length) {
9
+ let controller = new AbortController();
8
10
 
9
- const onabort = function (cancel) {
10
- if (!aborted) {
11
- aborted = true;
12
- unsubscribe();
13
- const err = cancel instanceof Error ? cancel : this.reason;
14
- controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
15
- }
16
- }
11
+ let aborted;
17
12
 
18
- let timer = timeout && setTimeout(() => {
19
- onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT))
20
- }, timeout)
13
+ const onabort = function (reason) {
14
+ if (!aborted) {
15
+ aborted = true;
16
+ unsubscribe();
17
+ const err = reason instanceof Error ? reason : this.reason;
18
+ controller.abort(err instanceof AxiosError ? err : new CanceledError(err instanceof Error ? err.message : err));
19
+ }
20
+ }
21
21
 
22
- const unsubscribe = () => {
23
- if (signals) {
24
- timer && clearTimeout(timer);
22
+ let timer = timeout && setTimeout(() => {
25
23
  timer = null;
26
- signals.forEach(signal => {
27
- signal &&
28
- (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
29
- });
30
- signals = null;
24
+ onabort(new AxiosError(`timeout ${timeout} of ms exceeded`, AxiosError.ETIMEDOUT))
25
+ }, timeout)
26
+
27
+ const unsubscribe = () => {
28
+ if (signals) {
29
+ timer && clearTimeout(timer);
30
+ timer = null;
31
+ signals.forEach(signal => {
32
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
33
+ });
34
+ signals = null;
35
+ }
31
36
  }
32
- }
33
37
 
34
- signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
38
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
35
39
 
36
- const {signal} = controller;
40
+ const {signal} = controller;
37
41
 
38
- signal.unsubscribe = unsubscribe;
42
+ signal.unsubscribe = () => utils.asap(unsubscribe);
39
43
 
40
- return [signal, () => {
41
- timer && clearTimeout(timer);
42
- timer = null;
43
- }];
44
+ return signal;
45
+ }
44
46
  }
45
47
 
46
48
  export default composeSignals;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "axios",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
4
4
  "description": "Promise based HTTP client for the browser and node.js",
5
5
  "main": "index.js",
6
6
  "exports": {