axios 1.6.8 → 1.7.0-beta.0
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 +12 -0
- package/README.md +30 -14
- package/dist/axios.js +954 -289
- 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 +651 -302
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +651 -302
- 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 +560 -240
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +5 -2
- package/index.d.ts +5 -2
- package/lib/adapters/adapters.js +3 -1
- package/lib/adapters/fetch.js +197 -0
- package/lib/adapters/xhr.js +31 -101
- package/lib/core/AxiosHeaders.js +4 -0
- package/lib/defaults/index.js +7 -2
- package/lib/env/data.js +1 -1
- package/lib/helpers/AxiosTransformStream.js +9 -8
- package/lib/helpers/composeSignals.js +46 -0
- package/lib/helpers/progressEventReducer.js +32 -0
- package/lib/helpers/resolveConfig.js +57 -0
- package/lib/helpers/throttle.js +5 -3
- package/lib/helpers/trackStream.js +56 -0
- package/lib/platform/common/utils.js +4 -1
- package/lib/utils.js +7 -2
- package/package.json +3 -2
@@ -0,0 +1,57 @@
|
|
1
|
+
import platform from "../platform/index.js";
|
2
|
+
import utils from "../utils.js";
|
3
|
+
import isURLSameOrigin from "./isURLSameOrigin.js";
|
4
|
+
import cookies from "./cookies.js";
|
5
|
+
import buildFullPath from "../core/buildFullPath.js";
|
6
|
+
import mergeConfig from "../core/mergeConfig.js";
|
7
|
+
import AxiosHeaders from "../core/AxiosHeaders.js";
|
8
|
+
import buildURL from "./buildURL.js";
|
9
|
+
|
10
|
+
export default (config) => {
|
11
|
+
const newConfig = mergeConfig({}, config);
|
12
|
+
|
13
|
+
let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
|
14
|
+
|
15
|
+
newConfig.headers = headers = AxiosHeaders.from(headers);
|
16
|
+
|
17
|
+
newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
|
18
|
+
|
19
|
+
// HTTP basic authentication
|
20
|
+
if (auth) {
|
21
|
+
headers.set('Authorization', 'Basic ' +
|
22
|
+
btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
|
23
|
+
);
|
24
|
+
}
|
25
|
+
|
26
|
+
let contentType;
|
27
|
+
|
28
|
+
if (utils.isFormData(data)) {
|
29
|
+
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
30
|
+
headers.setContentType(undefined); // Let the browser set it
|
31
|
+
} else if ((contentType = headers.getContentType()) !== false) {
|
32
|
+
// fix semicolon duplication issue for ReactNative FormData implementation
|
33
|
+
const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
|
34
|
+
headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
// Add xsrf header
|
39
|
+
// This is only done if running in a standard browser environment.
|
40
|
+
// Specifically not if we're in a web worker, or react-native.
|
41
|
+
|
42
|
+
if (platform.hasStandardBrowserEnv) {
|
43
|
+
withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
|
44
|
+
|
45
|
+
if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
|
46
|
+
// Add xsrf header
|
47
|
+
const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
|
48
|
+
|
49
|
+
if (xsrfValue) {
|
50
|
+
headers.set(xsrfHeaderName, xsrfValue);
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
return newConfig;
|
56
|
+
}
|
57
|
+
|
package/lib/helpers/throttle.js
CHANGED
@@ -10,7 +10,9 @@ function throttle(fn, freq) {
|
|
10
10
|
let timestamp = 0;
|
11
11
|
const threshold = 1000 / freq;
|
12
12
|
let timer = null;
|
13
|
-
return function throttled(
|
13
|
+
return function throttled() {
|
14
|
+
const force = this === true;
|
15
|
+
|
14
16
|
const now = Date.now();
|
15
17
|
if (force || now - timestamp > threshold) {
|
16
18
|
if (timer) {
|
@@ -18,13 +20,13 @@ function throttle(fn, freq) {
|
|
18
20
|
timer = null;
|
19
21
|
}
|
20
22
|
timestamp = now;
|
21
|
-
return fn.apply(null,
|
23
|
+
return fn.apply(null, arguments);
|
22
24
|
}
|
23
25
|
if (!timer) {
|
24
26
|
timer = setTimeout(() => {
|
25
27
|
timer = null;
|
26
28
|
timestamp = Date.now();
|
27
|
-
return fn.apply(null,
|
29
|
+
return fn.apply(null, arguments);
|
28
30
|
}, threshold - (now - timestamp));
|
29
31
|
}
|
30
32
|
};
|
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
export const streamChunk = function* (chunk, chunkSize) {
|
3
|
+
let len = chunk.byteLength;
|
4
|
+
|
5
|
+
if (!chunkSize || len < chunkSize) {
|
6
|
+
yield chunk;
|
7
|
+
return;
|
8
|
+
}
|
9
|
+
|
10
|
+
let pos = 0;
|
11
|
+
let end;
|
12
|
+
|
13
|
+
while (pos < len) {
|
14
|
+
end = pos + chunkSize;
|
15
|
+
yield chunk.slice(pos, end);
|
16
|
+
pos = end;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
const encoder = new TextEncoder();
|
21
|
+
|
22
|
+
export const readBytes = async function* (iterable, chunkSize) {
|
23
|
+
for await (const chunk of iterable) {
|
24
|
+
yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encoder.encode(String(chunk))), chunkSize);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
|
28
|
+
export const trackStream = (stream, chunkSize, onProgress, onFinish) => {
|
29
|
+
const iterator = readBytes(stream, chunkSize);
|
30
|
+
|
31
|
+
let bytes = 0;
|
32
|
+
|
33
|
+
return new ReadableStream({
|
34
|
+
type: 'bytes',
|
35
|
+
|
36
|
+
async pull(controller) {
|
37
|
+
const {done, value} = await iterator.next();
|
38
|
+
|
39
|
+
if (done) {
|
40
|
+
controller.close();
|
41
|
+
onFinish();
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
|
45
|
+
let len = value.byteLength;
|
46
|
+
onProgress && onProgress(bytes += len);
|
47
|
+
controller.enqueue(new Uint8Array(value));
|
48
|
+
},
|
49
|
+
cancel(reason) {
|
50
|
+
onFinish(reason);
|
51
|
+
return iterator.return();
|
52
|
+
}
|
53
|
+
}, {
|
54
|
+
highWaterMark: 2
|
55
|
+
})
|
56
|
+
}
|
@@ -40,8 +40,11 @@ const hasStandardBrowserWebWorkerEnv = (() => {
|
|
40
40
|
);
|
41
41
|
})();
|
42
42
|
|
43
|
+
const origin = hasBrowserEnv && window.location.href || 'http://localhost';
|
44
|
+
|
43
45
|
export {
|
44
46
|
hasBrowserEnv,
|
45
47
|
hasStandardBrowserWebWorkerEnv,
|
46
|
-
hasStandardBrowserEnv
|
48
|
+
hasStandardBrowserEnv,
|
49
|
+
origin
|
47
50
|
}
|
package/lib/utils.js
CHANGED
@@ -209,6 +209,8 @@ const isFormData = (thing) => {
|
|
209
209
|
*/
|
210
210
|
const isURLSearchParams = kindOfTest('URLSearchParams');
|
211
211
|
|
212
|
+
const [isReadableStream, isRequest, isResponse, isHeaders] = ['ReadableStream', 'Request', 'Response', 'Headers'].map(kindOfTest);
|
213
|
+
|
212
214
|
/**
|
213
215
|
* Trim excess whitespace off the beginning and end of a string
|
214
216
|
*
|
@@ -597,8 +599,7 @@ const toObjectSet = (arrayOrString, delimiter) => {
|
|
597
599
|
const noop = () => {}
|
598
600
|
|
599
601
|
const toFiniteNumber = (value, defaultValue) => {
|
600
|
-
value = +value;
|
601
|
-
return Number.isFinite(value) ? value : defaultValue;
|
602
|
+
return value != null && Number.isFinite(value = +value) ? value : defaultValue;
|
602
603
|
}
|
603
604
|
|
604
605
|
const ALPHA = 'abcdefghijklmnopqrstuvwxyz'
|
@@ -679,6 +680,10 @@ export default {
|
|
679
680
|
isBoolean,
|
680
681
|
isObject,
|
681
682
|
isPlainObject,
|
683
|
+
isReadableStream,
|
684
|
+
isRequest,
|
685
|
+
isResponse,
|
686
|
+
isHeaders,
|
682
687
|
isUndefined,
|
683
688
|
isDate,
|
684
689
|
isFile,
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.7.0-beta.0",
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
5
5
|
"main": "index.js",
|
6
6
|
"exports": {
|
@@ -135,7 +135,8 @@
|
|
135
135
|
"stream-throttle": "^0.1.3",
|
136
136
|
"string-replace-async": "^3.0.2",
|
137
137
|
"terser-webpack-plugin": "^4.2.3",
|
138
|
-
"typescript": "^4.9.5"
|
138
|
+
"typescript": "^4.9.5",
|
139
|
+
"@rollup/plugin-alias": "^5.1.0"
|
139
140
|
},
|
140
141
|
"browser": {
|
141
142
|
"./lib/adapters/http.js": "./lib/helpers/null.js",
|