axios 1.5.1 → 1.6.1
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 +175 -0
- package/README.md +256 -1
- package/dist/axios.js +191 -131
- 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 +143 -141
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +143 -141
- 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 +225 -159
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +18 -7
- package/index.d.ts +19 -8
- package/lib/adapters/http.js +23 -10
- package/lib/adapters/xhr.js +7 -8
- package/lib/env/data.js +1 -1
- package/lib/helpers/cookies.js +1 -1
- package/lib/helpers/isURLSameOrigin.js +1 -1
- package/lib/platform/browser/index.js +0 -51
- package/lib/platform/common/utils.js +47 -0
- package/lib/platform/index.js +5 -1
- package/package.json +2 -1
package/index.d.cts
CHANGED
@@ -8,6 +8,8 @@ type MethodsHeaders = Partial<{
|
|
8
8
|
|
9
9
|
type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string, headers: RawAxiosHeaders) => boolean;
|
10
10
|
|
11
|
+
type AxiosHeaderParser = (this: AxiosHeaders, value: axios.AxiosHeaderValue, header: string) => any;
|
12
|
+
|
11
13
|
type CommonRequestHeadersList = 'Accept' | 'Content-Length' | 'User-Agent'| 'Content-Encoding' | 'Authorization';
|
12
14
|
|
13
15
|
type ContentType = axios.AxiosHeaderValue | 'text/html' | 'text/plain' | 'multipart/form-data' | 'application/json' | 'application/x-www-form-urlencoded' | 'application/octet-stream';
|
@@ -16,18 +18,18 @@ type CommonResponseHeadersList = 'Server' | 'Content-Type' | 'Content-Length' |
|
|
16
18
|
|
17
19
|
declare class AxiosHeaders {
|
18
20
|
constructor(
|
19
|
-
headers?: RawAxiosHeaders | AxiosHeaders
|
21
|
+
headers?: RawAxiosHeaders | AxiosHeaders | string
|
20
22
|
);
|
21
23
|
|
22
24
|
[key: string]: any;
|
23
25
|
|
24
26
|
set(headerName?: string, value?: axios.AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
25
|
-
set(headers?: RawAxiosHeaders | AxiosHeaders, rewrite?: boolean): AxiosHeaders;
|
27
|
+
set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
|
26
28
|
|
27
29
|
get(headerName: string, parser: RegExp): RegExpExecArray | null;
|
28
|
-
get(headerName: string, matcher?: true |
|
30
|
+
get(headerName: string, matcher?: true | AxiosHeaderParser): axios.AxiosHeaderValue;
|
29
31
|
|
30
|
-
has(header: string, matcher?:
|
32
|
+
has(header: string, matcher?: AxiosHeaderMatcher): boolean;
|
31
33
|
|
32
34
|
delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;
|
33
35
|
|
@@ -359,6 +361,15 @@ declare namespace axios {
|
|
359
361
|
|
360
362
|
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
361
363
|
|
364
|
+
type AddressFamily = 4 | 6 | undefined;
|
365
|
+
|
366
|
+
interface LookupAddressEntry {
|
367
|
+
address: string;
|
368
|
+
family?: AddressFamily;
|
369
|
+
}
|
370
|
+
|
371
|
+
type LookupAddress = string | LookupAddressEntry;
|
372
|
+
|
362
373
|
interface AxiosRequestConfig<D = any> {
|
363
374
|
url?: string;
|
364
375
|
method?: Method | string;
|
@@ -400,9 +411,9 @@ declare namespace axios {
|
|
400
411
|
FormData?: new (...args: any[]) => object;
|
401
412
|
};
|
402
413
|
formSerializer?: FormSerializerOptions;
|
403
|
-
family?:
|
404
|
-
lookup?: ((hostname: string, options: object, cb: (err: Error | null, address:
|
405
|
-
((hostname: string, options: object) => Promise<[address:
|
414
|
+
family?: AddressFamily;
|
415
|
+
lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
|
416
|
+
((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
|
406
417
|
}
|
407
418
|
|
408
419
|
// Alias
|
package/index.d.ts
CHANGED
@@ -9,22 +9,24 @@ type MethodsHeaders = Partial<{
|
|
9
9
|
[Key in Method as Lowercase<Key>]: AxiosHeaders;
|
10
10
|
} & {common: AxiosHeaders}>;
|
11
11
|
|
12
|
-
type AxiosHeaderMatcher = (this: AxiosHeaders, value: string, name: string
|
12
|
+
type AxiosHeaderMatcher = string | RegExp | ((this: AxiosHeaders, value: string, name: string) => boolean);
|
13
|
+
|
14
|
+
type AxiosHeaderParser = (this: AxiosHeaders, value: AxiosHeaderValue, header: string) => any;
|
13
15
|
|
14
16
|
export class AxiosHeaders {
|
15
17
|
constructor(
|
16
|
-
headers?: RawAxiosHeaders | AxiosHeaders
|
18
|
+
headers?: RawAxiosHeaders | AxiosHeaders | string
|
17
19
|
);
|
18
20
|
|
19
21
|
[key: string]: any;
|
20
22
|
|
21
23
|
set(headerName?: string, value?: AxiosHeaderValue, rewrite?: boolean | AxiosHeaderMatcher): AxiosHeaders;
|
22
|
-
set(headers?: RawAxiosHeaders | AxiosHeaders, rewrite?: boolean): AxiosHeaders;
|
24
|
+
set(headers?: RawAxiosHeaders | AxiosHeaders | string, rewrite?: boolean): AxiosHeaders;
|
23
25
|
|
24
26
|
get(headerName: string, parser: RegExp): RegExpExecArray | null;
|
25
|
-
get(headerName: string, matcher?: true |
|
27
|
+
get(headerName: string, matcher?: true | AxiosHeaderParser): AxiosHeaderValue;
|
26
28
|
|
27
|
-
has(header: string, matcher?:
|
29
|
+
has(header: string, matcher?: AxiosHeaderMatcher): boolean;
|
28
30
|
|
29
31
|
delete(header: string | string[], matcher?: AxiosHeaderMatcher): boolean;
|
30
32
|
|
@@ -300,6 +302,15 @@ type AxiosAdapterName = 'xhr' | 'http' | string;
|
|
300
302
|
|
301
303
|
type AxiosAdapterConfig = AxiosAdapter | AxiosAdapterName;
|
302
304
|
|
305
|
+
export type AddressFamily = 4 | 6 | undefined;
|
306
|
+
|
307
|
+
export interface LookupAddressEntry {
|
308
|
+
address: string;
|
309
|
+
family?: AddressFamily;
|
310
|
+
}
|
311
|
+
|
312
|
+
export type LookupAddress = string | LookupAddressEntry;
|
313
|
+
|
303
314
|
export interface AxiosRequestConfig<D = any> {
|
304
315
|
url?: string;
|
305
316
|
method?: Method | string;
|
@@ -341,9 +352,9 @@ export interface AxiosRequestConfig<D = any> {
|
|
341
352
|
FormData?: new (...args: any[]) => object;
|
342
353
|
};
|
343
354
|
formSerializer?: FormSerializerOptions;
|
344
|
-
family?:
|
345
|
-
lookup?: ((hostname: string, options: object, cb: (err: Error | null, address:
|
346
|
-
((hostname: string, options: object) => Promise<[address:
|
355
|
+
family?: AddressFamily;
|
356
|
+
lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: LookupAddress | LookupAddress[], family?: AddressFamily) => void) => void) |
|
357
|
+
((hostname: string, options: object) => Promise<[address: LookupAddressEntry | LookupAddressEntry[], family?: AddressFamily] | LookupAddress>);
|
347
358
|
}
|
348
359
|
|
349
360
|
// Alias
|
package/lib/adapters/http.js
CHANGED
@@ -144,6 +144,18 @@ const wrapAsync = (asyncExecutor) => {
|
|
144
144
|
})
|
145
145
|
};
|
146
146
|
|
147
|
+
const resolveFamily = ({address, family}) => {
|
148
|
+
if (!utils.isString(address)) {
|
149
|
+
throw TypeError('address must be a string');
|
150
|
+
}
|
151
|
+
return ({
|
152
|
+
address,
|
153
|
+
family: family || (address.indexOf('.') < 0 ? 6 : 4)
|
154
|
+
});
|
155
|
+
}
|
156
|
+
|
157
|
+
const buildAddressEntry = (address, family) => resolveFamily(utils.isObject(address) ? address : {address, family});
|
158
|
+
|
147
159
|
/*eslint consistent-return:0*/
|
148
160
|
export default isHttpAdapterSupported && function httpAdapter(config) {
|
149
161
|
return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
|
@@ -154,15 +166,16 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
154
166
|
let rejected = false;
|
155
167
|
let req;
|
156
168
|
|
157
|
-
if (lookup
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
169
|
+
if (lookup) {
|
170
|
+
const _lookup = callbackify(lookup, (value) => utils.isArray(value) ? value : [value]);
|
171
|
+
// hotfix to support opt.all option which is required for node 20.x
|
172
|
+
lookup = (hostname, opt, cb) => {
|
173
|
+
_lookup(hostname, opt, (err, arg0, arg1) => {
|
174
|
+
const addresses = utils.isArray(arg0) ? arg0.map(addr => buildAddressEntry(addr)) : [buildAddressEntry(arg0, arg1)];
|
175
|
+
|
176
|
+
opt.all ? cb(err, addresses) : cb(err, addresses[0].address, addresses[0].family);
|
177
|
+
});
|
178
|
+
}
|
166
179
|
}
|
167
180
|
|
168
181
|
// temporary internal emitter until the AxiosRequest class will be implemented
|
@@ -567,7 +580,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
567
580
|
}
|
568
581
|
response.data = responseData;
|
569
582
|
} catch (err) {
|
570
|
-
reject(AxiosError.from(err, null, config, response.request, response));
|
583
|
+
return reject(AxiosError.from(err, null, config, response.request, response));
|
571
584
|
}
|
572
585
|
settle(resolve, reject, response);
|
573
586
|
});
|
package/lib/adapters/xhr.js
CHANGED
@@ -64,13 +64,12 @@ export default isXHRAdapterSupported && function (config) {
|
|
64
64
|
let contentType;
|
65
65
|
|
66
66
|
if (utils.isFormData(requestData)) {
|
67
|
-
if (platform.
|
67
|
+
if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
|
68
68
|
requestHeaders.setContentType(false); // Let the browser set it
|
69
|
-
} else if(
|
70
|
-
requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
|
71
|
-
} else if(utils.isString(contentType = requestHeaders.getContentType())){
|
69
|
+
} else if ((contentType = requestHeaders.getContentType()) !== false) {
|
72
70
|
// fix semicolon duplication issue for ReactNative FormData implementation
|
73
|
-
|
71
|
+
const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
|
72
|
+
requestHeaders.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
|
74
73
|
}
|
75
74
|
}
|
76
75
|
|
@@ -186,10 +185,10 @@ export default isXHRAdapterSupported && function (config) {
|
|
186
185
|
// Add xsrf header
|
187
186
|
// This is only done if running in a standard browser environment.
|
188
187
|
// Specifically not if we're in a web worker, or react-native.
|
189
|
-
if (platform.
|
188
|
+
if (platform.hasStandardBrowserEnv) {
|
190
189
|
// Add xsrf header
|
191
|
-
|
192
|
-
|
190
|
+
// regarding CVE-2023-45857 config.withCredentials condition was removed temporarily
|
191
|
+
const xsrfValue = isURLSameOrigin(fullPath) && config.xsrfCookieName && cookies.read(config.xsrfCookieName);
|
193
192
|
|
194
193
|
if (xsrfValue) {
|
195
194
|
requestHeaders.set(config.xsrfHeaderName, xsrfValue);
|
package/lib/env/data.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "1.
|
1
|
+
export const VERSION = "1.6.1";
|
package/lib/helpers/cookies.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
import utils from './../utils.js';
|
4
4
|
import platform from '../platform/index.js';
|
5
5
|
|
6
|
-
export default platform.
|
6
|
+
export default platform.hasStandardBrowserEnv ?
|
7
7
|
|
8
8
|
// Standard browser envs support document.cookie
|
9
9
|
(function standardBrowserEnv() {
|
@@ -3,7 +3,7 @@
|
|
3
3
|
import utils from './../utils.js';
|
4
4
|
import platform from '../platform/index.js';
|
5
5
|
|
6
|
-
export default platform.
|
6
|
+
export default platform.hasStandardBrowserEnv ?
|
7
7
|
|
8
8
|
// Standard browser envs have full support of the APIs needed to test
|
9
9
|
// whether the request URL is of the same origin as current location.
|
@@ -2,55 +2,6 @@ import URLSearchParams from './classes/URLSearchParams.js'
|
|
2
2
|
import FormData from './classes/FormData.js'
|
3
3
|
import Blob from './classes/Blob.js'
|
4
4
|
|
5
|
-
/**
|
6
|
-
* Determine if we're running in a standard browser environment
|
7
|
-
*
|
8
|
-
* This allows axios to run in a web worker, and react-native.
|
9
|
-
* Both environments support XMLHttpRequest, but not fully standard globals.
|
10
|
-
*
|
11
|
-
* web workers:
|
12
|
-
* typeof window -> undefined
|
13
|
-
* typeof document -> undefined
|
14
|
-
*
|
15
|
-
* react-native:
|
16
|
-
* navigator.product -> 'ReactNative'
|
17
|
-
* nativescript
|
18
|
-
* navigator.product -> 'NativeScript' or 'NS'
|
19
|
-
*
|
20
|
-
* @returns {boolean}
|
21
|
-
*/
|
22
|
-
const isStandardBrowserEnv = (() => {
|
23
|
-
let product;
|
24
|
-
if (typeof navigator !== 'undefined' && (
|
25
|
-
(product = navigator.product) === 'ReactNative' ||
|
26
|
-
product === 'NativeScript' ||
|
27
|
-
product === 'NS')
|
28
|
-
) {
|
29
|
-
return false;
|
30
|
-
}
|
31
|
-
|
32
|
-
return typeof window !== 'undefined' && typeof document !== 'undefined';
|
33
|
-
})();
|
34
|
-
|
35
|
-
/**
|
36
|
-
* Determine if we're running in a standard browser webWorker environment
|
37
|
-
*
|
38
|
-
* Although the `isStandardBrowserEnv` method indicates that
|
39
|
-
* `allows axios to run in a web worker`, the WebWorker will still be
|
40
|
-
* filtered out due to its judgment standard
|
41
|
-
* `typeof window !== 'undefined' && typeof document !== 'undefined'`.
|
42
|
-
* This leads to a problem when axios post `FormData` in webWorker
|
43
|
-
*/
|
44
|
-
const isStandardBrowserWebWorkerEnv = (() => {
|
45
|
-
return (
|
46
|
-
typeof WorkerGlobalScope !== 'undefined' &&
|
47
|
-
// eslint-disable-next-line no-undef
|
48
|
-
self instanceof WorkerGlobalScope &&
|
49
|
-
typeof self.importScripts === 'function'
|
50
|
-
);
|
51
|
-
})();
|
52
|
-
|
53
|
-
|
54
5
|
export default {
|
55
6
|
isBrowser: true,
|
56
7
|
classes: {
|
@@ -58,7 +9,5 @@ export default {
|
|
58
9
|
FormData,
|
59
10
|
Blob
|
60
11
|
},
|
61
|
-
isStandardBrowserEnv,
|
62
|
-
isStandardBrowserWebWorkerEnv,
|
63
12
|
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
|
64
13
|
};
|
@@ -0,0 +1,47 @@
|
|
1
|
+
const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Determine if we're running in a standard browser environment
|
5
|
+
*
|
6
|
+
* This allows axios to run in a web worker, and react-native.
|
7
|
+
* Both environments support XMLHttpRequest, but not fully standard globals.
|
8
|
+
*
|
9
|
+
* web workers:
|
10
|
+
* typeof window -> undefined
|
11
|
+
* typeof document -> undefined
|
12
|
+
*
|
13
|
+
* react-native:
|
14
|
+
* navigator.product -> 'ReactNative'
|
15
|
+
* nativescript
|
16
|
+
* navigator.product -> 'NativeScript' or 'NS'
|
17
|
+
*
|
18
|
+
* @returns {boolean}
|
19
|
+
*/
|
20
|
+
const hasStandardBrowserEnv = (
|
21
|
+
(product) => {
|
22
|
+
return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
|
23
|
+
})(typeof navigator !== 'undefined' && navigator.product);
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Determine if we're running in a standard browser webWorker environment
|
27
|
+
*
|
28
|
+
* Although the `isStandardBrowserEnv` method indicates that
|
29
|
+
* `allows axios to run in a web worker`, the WebWorker will still be
|
30
|
+
* filtered out due to its judgment standard
|
31
|
+
* `typeof window !== 'undefined' && typeof document !== 'undefined'`.
|
32
|
+
* This leads to a problem when axios post `FormData` in webWorker
|
33
|
+
*/
|
34
|
+
const hasStandardBrowserWebWorkerEnv = (() => {
|
35
|
+
return (
|
36
|
+
typeof WorkerGlobalScope !== 'undefined' &&
|
37
|
+
// eslint-disable-next-line no-undef
|
38
|
+
self instanceof WorkerGlobalScope &&
|
39
|
+
typeof self.importScripts === 'function'
|
40
|
+
);
|
41
|
+
})();
|
42
|
+
|
43
|
+
export {
|
44
|
+
hasBrowserEnv,
|
45
|
+
hasStandardBrowserWebWorkerEnv,
|
46
|
+
hasStandardBrowserEnv
|
47
|
+
}
|
package/lib/platform/index.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.6.1",
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
5
5
|
"main": "index.js",
|
6
6
|
"exports": {
|
@@ -121,6 +121,7 @@
|
|
121
121
|
"karma-sauce-launcher": "^4.3.6",
|
122
122
|
"karma-sinon": "^1.0.5",
|
123
123
|
"karma-sourcemap-loader": "^0.3.8",
|
124
|
+
"memoizee": "^0.4.15",
|
124
125
|
"minimist": "^1.2.7",
|
125
126
|
"mocha": "^10.0.0",
|
126
127
|
"multer": "^1.4.4",
|