axios 1.7.0-beta.0 → 1.7.0-beta.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.
- package/CHANGELOG.md +27 -0
- package/dist/axios.js +90 -57
- 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 +60 -33
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +60 -33
- 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 +60 -33
- package/dist/node/axios.cjs.map +1 -1
- package/lib/adapters/fetch.js +49 -25
- package/lib/core/Axios.js +9 -6
- package/lib/env/data.js +1 -1
- package/package.json +1 -1
package/lib/adapters/fetch.js
CHANGED
@@ -18,8 +18,9 @@ const fetchProgressDecorator = (total, fn) => {
|
|
18
18
|
}
|
19
19
|
|
20
20
|
const isFetchSupported = typeof fetch !== 'undefined';
|
21
|
+
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined';
|
21
22
|
|
22
|
-
const
|
23
|
+
const supportsRequestStream = isReadableStreamSupported && (() => {
|
23
24
|
let duplexAccessed = false;
|
24
25
|
|
25
26
|
const hasContentType = new Request(platform.origin, {
|
@@ -36,17 +37,32 @@ const supportsRequestStreams = isFetchSupported && (() => {
|
|
36
37
|
|
37
38
|
const DEFAULT_CHUNK_SIZE = 64 * 1024;
|
38
39
|
|
40
|
+
const supportsResponseStream = isReadableStreamSupported && !!(()=> {
|
41
|
+
try {
|
42
|
+
return utils.isReadableStream(new Response('').body);
|
43
|
+
} catch(err) {
|
44
|
+
// return undefined
|
45
|
+
}
|
46
|
+
})();
|
47
|
+
|
39
48
|
const resolvers = {
|
40
|
-
stream: (res) => res.body
|
49
|
+
stream: supportsResponseStream && ((res) => res.body)
|
41
50
|
};
|
42
51
|
|
43
|
-
isFetchSupported &&
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
52
|
+
isFetchSupported && (((res) => {
|
53
|
+
['text', 'arrayBuffer', 'blob', 'formData', 'stream'].forEach(type => {
|
54
|
+
!resolvers[type] && (resolvers[type] = utils.isFunction(res[type]) ? (res) => res[type]() :
|
55
|
+
(_, config) => {
|
56
|
+
throw new AxiosError(`Response type '${type}' is not supported`, AxiosError.ERR_NOT_SUPPORT, config);
|
57
|
+
})
|
58
|
+
});
|
59
|
+
})(new Response));
|
48
60
|
|
49
61
|
const getBodyLength = async (body) => {
|
62
|
+
if (body == null) {
|
63
|
+
return 0;
|
64
|
+
}
|
65
|
+
|
50
66
|
if(utils.isBlob(body)) {
|
51
67
|
return body.size;
|
52
68
|
}
|
@@ -74,7 +90,7 @@ const resolveBodyLength = async (headers, body) => {
|
|
74
90
|
return length == null ? getBodyLength(body) : length;
|
75
91
|
}
|
76
92
|
|
77
|
-
export default async (config) => {
|
93
|
+
export default isFetchSupported && (async (config) => {
|
78
94
|
let {
|
79
95
|
url,
|
80
96
|
method,
|
@@ -105,12 +121,15 @@ export default async (config) => {
|
|
105
121
|
finished = true;
|
106
122
|
}
|
107
123
|
|
108
|
-
|
109
|
-
if (onUploadProgress && supportsRequestStreams && method !== 'get' && method !== 'head') {
|
110
|
-
let requestContentLength = await resolveBodyLength(headers, data);
|
124
|
+
let requestContentLength;
|
111
125
|
|
126
|
+
try {
|
127
|
+
if (
|
128
|
+
onUploadProgress && supportsRequestStream && method !== 'get' && method !== 'head' &&
|
129
|
+
(requestContentLength = await resolveBodyLength(headers, data)) !== 0
|
130
|
+
) {
|
112
131
|
let _request = new Request(url, {
|
113
|
-
method,
|
132
|
+
method: 'POST',
|
114
133
|
body: data,
|
115
134
|
duplex: "half"
|
116
135
|
});
|
@@ -121,10 +140,12 @@ export default async (config) => {
|
|
121
140
|
headers.setContentType(contentTypeHeader)
|
122
141
|
}
|
123
142
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
143
|
+
if (_request.body) {
|
144
|
+
data = trackStream(_request.body, DEFAULT_CHUNK_SIZE, fetchProgressDecorator(
|
145
|
+
requestContentLength,
|
146
|
+
progressEventReducer(onUploadProgress)
|
147
|
+
));
|
148
|
+
}
|
128
149
|
}
|
129
150
|
|
130
151
|
if (!utils.isString(withCredentials)) {
|
@@ -134,7 +155,7 @@ export default async (config) => {
|
|
134
155
|
request = new Request(url, {
|
135
156
|
...fetchOptions,
|
136
157
|
signal: composedSignal,
|
137
|
-
method,
|
158
|
+
method: method.toUpperCase(),
|
138
159
|
headers: headers.normalize().toJSON(),
|
139
160
|
body: data,
|
140
161
|
duplex: "half",
|
@@ -145,10 +166,10 @@ export default async (config) => {
|
|
145
166
|
|
146
167
|
const isStreamResponse = responseType === 'stream' || responseType === 'response';
|
147
168
|
|
148
|
-
if (onDownloadProgress || isStreamResponse) {
|
169
|
+
if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
|
149
170
|
const options = {};
|
150
171
|
|
151
|
-
|
172
|
+
['status', 'statusText', 'headers'].forEach(prop => {
|
152
173
|
options[prop] = response[prop];
|
153
174
|
});
|
154
175
|
|
@@ -184,14 +205,17 @@ export default async (config) => {
|
|
184
205
|
} catch (err) {
|
185
206
|
onFinish();
|
186
207
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
208
|
+
if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
|
209
|
+
throw Object.assign(
|
210
|
+
new AxiosError('Network Error', AxiosError.ERR_NETWORK, config, request),
|
211
|
+
{
|
212
|
+
cause: err.cause || err
|
213
|
+
}
|
214
|
+
)
|
191
215
|
}
|
192
216
|
|
193
|
-
throw AxiosError.from(err, code, config, request);
|
217
|
+
throw AxiosError.from(err, err && err.code, config, request);
|
194
218
|
}
|
195
|
-
}
|
219
|
+
});
|
196
220
|
|
197
221
|
|
package/lib/core/Axios.js
CHANGED
@@ -46,12 +46,15 @@ class Axios {
|
|
46
46
|
|
47
47
|
// slice off the Error: ... line
|
48
48
|
const stack = dummy.stack ? dummy.stack.replace(/^.+\n/, '') : '';
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
try {
|
50
|
+
if (!err.stack) {
|
51
|
+
err.stack = stack;
|
52
|
+
// match without the 2 top stack lines
|
53
|
+
} else if (stack && !String(err.stack).endsWith(stack.replace(/^.+\n.+\n/, ''))) {
|
54
|
+
err.stack += '\n' + stack
|
55
|
+
}
|
56
|
+
} catch (e) {
|
57
|
+
// ignore the case where "stack" is an un-writable property
|
55
58
|
}
|
56
59
|
}
|
57
60
|
|
package/lib/env/data.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "1.7.0-beta.
|
1
|
+
export const VERSION = "1.7.0-beta.2";
|