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.
- package/CHANGELOG.md +14 -0
- package/README.md +4 -3
- package/dist/axios.js +84 -65
- package/dist/axios.js.map +1 -1
- package/dist/axios.min.js +1 -1
- package/dist/axios.min.js.map +1 -1
- package/dist/browser/axios.cjs +62 -50
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +62 -50
- package/dist/esm/axios.js.map +1 -1
- package/dist/esm/axios.min.js +1 -1
- package/dist/esm/axios.min.js.map +1 -1
- package/dist/node/axios.cjs +62 -50
- package/dist/node/axios.cjs.map +1 -1
- package/lib/adapters/fetch.js +15 -18
- package/lib/cancel/CancelToken.js +14 -0
- package/lib/env/data.js +1 -1
- package/lib/helpers/composeSignals.js +31 -29
- package/package.json +1 -1
package/lib/adapters/fetch.js
CHANGED
@@ -69,7 +69,11 @@ const getBodyLength = async (body) => {
|
|
69
69
|
}
|
70
70
|
|
71
71
|
if(utils.isSpecCompliantForm(body)) {
|
72
|
-
|
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
|
113
|
-
composeSignals([signal, cancelToken], timeout) : [];
|
114
|
-
|
115
|
-
let finished, request;
|
116
|
+
let composedSignal = composeSignals([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
|
116
117
|
|
117
|
-
|
118
|
-
!finished && setTimeout(() => {
|
119
|
-
composedSignal && composedSignal.unsubscribe();
|
120
|
-
});
|
118
|
+
let request;
|
121
119
|
|
122
|
-
|
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
|
-
|
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 &&
|
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
|
-
|
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.
|
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
|
-
|
6
|
+
const {length} = (signals = signals ? signals.filter(Boolean) : []);
|
6
7
|
|
7
|
-
|
8
|
+
if (timeout || length) {
|
9
|
+
let controller = new AbortController();
|
8
10
|
|
9
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
23
|
-
if (signals) {
|
24
|
-
timer && clearTimeout(timer);
|
22
|
+
let timer = timeout && setTimeout(() => {
|
25
23
|
timer = null;
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
signals
|
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
|
-
|
38
|
+
signals.forEach((signal) => signal.addEventListener('abort', onabort));
|
35
39
|
|
36
|
-
|
40
|
+
const {signal} = controller;
|
37
41
|
|
38
|
-
|
42
|
+
signal.unsubscribe = () => utils.asap(unsubscribe);
|
39
43
|
|
40
|
-
|
41
|
-
|
42
|
-
timer = null;
|
43
|
-
}];
|
44
|
+
return signal;
|
45
|
+
}
|
44
46
|
}
|
45
47
|
|
46
48
|
export default composeSignals;
|