axios 1.4.0 → 1.5.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 +42 -0
- package/README.md +45 -11
- package/dist/axios.js +56 -28
- 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 +63 -36
- package/dist/browser/axios.cjs.map +1 -1
- package/dist/esm/axios.js +65 -37
- 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 +68 -39
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +2 -4
- package/index.d.ts +4 -4
- package/index.js +2 -0
- package/lib/adapters/adapters.js +33 -15
- package/lib/adapters/http.js +5 -3
- package/lib/adapters/xhr.js +7 -2
- package/lib/axios.js +3 -0
- package/lib/core/Axios.js +2 -4
- package/lib/core/AxiosHeaders.js +11 -1
- package/lib/defaults/index.js +3 -10
- package/lib/env/data.js +1 -1
- package/lib/utils.js +3 -2
- package/package.json +3 -1
package/index.d.cts
CHANGED
@@ -244,10 +244,7 @@ declare namespace axios {
|
|
244
244
|
interface AxiosProxyConfig {
|
245
245
|
host: string;
|
246
246
|
port: number;
|
247
|
-
auth?:
|
248
|
-
username: string;
|
249
|
-
password: string;
|
250
|
-
};
|
247
|
+
auth?: AxiosBasicCredentials;
|
251
248
|
protocol?: string;
|
252
249
|
}
|
253
250
|
|
@@ -523,6 +520,7 @@ declare namespace axios {
|
|
523
520
|
isAxiosError<T = any, D = any>(payload: any): payload is AxiosError<T, D>;
|
524
521
|
toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
525
522
|
formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
523
|
+
getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
|
526
524
|
AxiosHeaders: typeof AxiosHeaders;
|
527
525
|
}
|
528
526
|
}
|
package/index.d.ts
CHANGED
@@ -119,10 +119,7 @@ export interface AxiosBasicCredentials {
|
|
119
119
|
export interface AxiosProxyConfig {
|
120
120
|
host: string;
|
121
121
|
port: number;
|
122
|
-
auth?:
|
123
|
-
username: string;
|
124
|
-
password: string;
|
125
|
-
};
|
122
|
+
auth?: AxiosBasicCredentials;
|
126
123
|
protocol?: string;
|
127
124
|
}
|
128
125
|
|
@@ -512,6 +509,8 @@ export interface GenericHTMLFormElement {
|
|
512
509
|
submit(): void;
|
513
510
|
}
|
514
511
|
|
512
|
+
export function getAdapter(adapters: AxiosAdapterConfig | AxiosAdapterConfig[] | undefined): AxiosAdapter;
|
513
|
+
|
515
514
|
export function toFormData(sourceObj: object, targetFormData?: GenericFormData, options?: FormSerializerOptions): GenericFormData;
|
516
515
|
|
517
516
|
export function formToJSON(form: GenericFormData|GenericHTMLFormElement): object;
|
@@ -538,6 +537,7 @@ export interface AxiosStatic extends AxiosInstance {
|
|
538
537
|
isAxiosError: typeof isAxiosError;
|
539
538
|
toFormData: typeof toFormData;
|
540
539
|
formToJSON: typeof formToJSON;
|
540
|
+
getAdapter: typeof getAdapter;
|
541
541
|
CanceledError: typeof CanceledError;
|
542
542
|
AxiosHeaders: typeof AxiosHeaders;
|
543
543
|
}
|
package/index.js
CHANGED
package/lib/adapters/adapters.js
CHANGED
@@ -9,7 +9,7 @@ const knownAdapters = {
|
|
9
9
|
}
|
10
10
|
|
11
11
|
utils.forEach(knownAdapters, (fn, value) => {
|
12
|
-
if(fn) {
|
12
|
+
if (fn) {
|
13
13
|
try {
|
14
14
|
Object.defineProperty(fn, 'name', {value});
|
15
15
|
} catch (e) {
|
@@ -19,6 +19,10 @@ utils.forEach(knownAdapters, (fn, value) => {
|
|
19
19
|
}
|
20
20
|
});
|
21
21
|
|
22
|
+
const renderReason = (reason) => `- ${reason}`;
|
23
|
+
|
24
|
+
const isResolvedHandle = (adapter) => utils.isFunction(adapter) || adapter === null || adapter === false;
|
25
|
+
|
22
26
|
export default {
|
23
27
|
getAdapter: (adapters) => {
|
24
28
|
adapters = utils.isArray(adapters) ? adapters : [adapters];
|
@@ -27,30 +31,44 @@ export default {
|
|
27
31
|
let nameOrAdapter;
|
28
32
|
let adapter;
|
29
33
|
|
34
|
+
const rejectedReasons = {};
|
35
|
+
|
30
36
|
for (let i = 0; i < length; i++) {
|
31
37
|
nameOrAdapter = adapters[i];
|
32
|
-
|
38
|
+
let id;
|
39
|
+
|
40
|
+
adapter = nameOrAdapter;
|
41
|
+
|
42
|
+
if (!isResolvedHandle(nameOrAdapter)) {
|
43
|
+
adapter = knownAdapters[(id = String(nameOrAdapter)).toLowerCase()];
|
44
|
+
|
45
|
+
if (adapter === undefined) {
|
46
|
+
throw new AxiosError(`Unknown adapter '${id}'`);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
if (adapter) {
|
33
51
|
break;
|
34
52
|
}
|
53
|
+
|
54
|
+
rejectedReasons[id || '#' + i] = adapter;
|
35
55
|
}
|
36
56
|
|
37
57
|
if (!adapter) {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
'
|
58
|
+
|
59
|
+
const reasons = Object.entries(rejectedReasons)
|
60
|
+
.map(([id, state]) => `adapter ${id} ` +
|
61
|
+
(state === false ? 'is not supported by the environment' : 'is not available in the build')
|
42
62
|
);
|
43
|
-
}
|
44
63
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
`Unknown adapter '${nameOrAdapter}'`
|
49
|
-
);
|
50
|
-
}
|
64
|
+
let s = length ?
|
65
|
+
(reasons.length > 1 ? 'since :\n' + reasons.map(renderReason).join('\n') : ' ' + renderReason(reasons[0])) :
|
66
|
+
'as no adapter specified';
|
51
67
|
|
52
|
-
|
53
|
-
|
68
|
+
throw new AxiosError(
|
69
|
+
`There is no suitable adapter to dispatch the request ` + s,
|
70
|
+
'ERR_NOT_SUPPORT'
|
71
|
+
);
|
54
72
|
}
|
55
73
|
|
56
74
|
return adapter;
|
package/lib/adapters/http.js
CHANGED
@@ -391,11 +391,13 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
391
391
|
auth,
|
392
392
|
protocol,
|
393
393
|
family,
|
394
|
-
lookup,
|
395
394
|
beforeRedirect: dispatchBeforeRedirect,
|
396
395
|
beforeRedirects: {}
|
397
396
|
};
|
398
397
|
|
398
|
+
// cacheable-lookup integration hotfix
|
399
|
+
!utils.isUndefined(lookup) && (options.lookup = lookup);
|
400
|
+
|
399
401
|
if (config.socketPath) {
|
400
402
|
options.socketPath = config.socketPath;
|
401
403
|
} else {
|
@@ -469,7 +471,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
469
471
|
delete res.headers['content-encoding'];
|
470
472
|
}
|
471
473
|
|
472
|
-
switch (res.headers['content-encoding']) {
|
474
|
+
switch ((res.headers['content-encoding'] || '').toLowerCase()) {
|
473
475
|
/*eslint default-case:0*/
|
474
476
|
case 'gzip':
|
475
477
|
case 'x-gzip':
|
@@ -602,7 +604,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
|
|
602
604
|
// This is forcing a int timeout to avoid problems if the `req` interface doesn't handle other types.
|
603
605
|
const timeout = parseInt(config.timeout, 10);
|
604
606
|
|
605
|
-
if (isNaN(timeout)) {
|
607
|
+
if (Number.isNaN(timeout)) {
|
606
608
|
reject(new AxiosError(
|
607
609
|
'error trying to parse `config.timeout` to int',
|
608
610
|
AxiosError.ERR_BAD_OPTION_VALUE,
|
package/lib/adapters/xhr.js
CHANGED
@@ -61,11 +61,16 @@ export default isXHRAdapterSupported && function (config) {
|
|
61
61
|
}
|
62
62
|
}
|
63
63
|
|
64
|
+
let contentType;
|
65
|
+
|
64
66
|
if (utils.isFormData(requestData)) {
|
65
67
|
if (platform.isStandardBrowserEnv || platform.isStandardBrowserWebWorkerEnv) {
|
66
68
|
requestHeaders.setContentType(false); // Let the browser set it
|
67
|
-
} else {
|
68
|
-
requestHeaders.setContentType('multipart/form-data
|
69
|
+
} else if(!requestHeaders.getContentType(/^\s*multipart\/form-data/)){
|
70
|
+
requestHeaders.setContentType('multipart/form-data'); // mobile/desktop app frameworks
|
71
|
+
} else if(utils.isString(contentType = requestHeaders.getContentType())){
|
72
|
+
// fix semicolon duplication issue for ReactNative FormData implementation
|
73
|
+
requestHeaders.setContentType(contentType.replace(/^\s*(multipart\/form-data);+/, '$1'))
|
69
74
|
}
|
70
75
|
}
|
71
76
|
|
package/lib/axios.js
CHANGED
@@ -15,6 +15,7 @@ import AxiosError from './core/AxiosError.js';
|
|
15
15
|
import spread from './helpers/spread.js';
|
16
16
|
import isAxiosError from './helpers/isAxiosError.js';
|
17
17
|
import AxiosHeaders from "./core/AxiosHeaders.js";
|
18
|
+
import adapters from './adapters/adapters.js';
|
18
19
|
import HttpStatusCode from './helpers/HttpStatusCode.js';
|
19
20
|
|
20
21
|
/**
|
@@ -78,6 +79,8 @@ axios.AxiosHeaders = AxiosHeaders;
|
|
78
79
|
|
79
80
|
axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
80
81
|
|
82
|
+
axios.getAdapter = adapters.getAdapter;
|
83
|
+
|
81
84
|
axios.HttpStatusCode = HttpStatusCode;
|
82
85
|
|
83
86
|
axios.default = axios;
|
package/lib/core/Axios.js
CHANGED
@@ -73,15 +73,13 @@ class Axios {
|
|
73
73
|
// Set config.method
|
74
74
|
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
75
75
|
|
76
|
-
let contextHeaders;
|
77
|
-
|
78
76
|
// Flatten headers
|
79
|
-
contextHeaders = headers && utils.merge(
|
77
|
+
let contextHeaders = headers && utils.merge(
|
80
78
|
headers.common,
|
81
79
|
headers[config.method]
|
82
80
|
);
|
83
81
|
|
84
|
-
|
82
|
+
headers && utils.forEach(
|
85
83
|
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
86
84
|
(method) => {
|
87
85
|
delete headers[method];
|
package/lib/core/AxiosHeaders.js
CHANGED
@@ -282,7 +282,17 @@ class AxiosHeaders {
|
|
282
282
|
|
283
283
|
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent', 'Authorization']);
|
284
284
|
|
285
|
-
|
285
|
+
// reserved names hotfix
|
286
|
+
utils.reduceDescriptors(AxiosHeaders.prototype, ({value}, key) => {
|
287
|
+
let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
|
288
|
+
return {
|
289
|
+
get: () => value,
|
290
|
+
set(headerValue) {
|
291
|
+
this[mapped] = headerValue;
|
292
|
+
}
|
293
|
+
}
|
294
|
+
});
|
295
|
+
|
286
296
|
utils.freezeMethods(AxiosHeaders);
|
287
297
|
|
288
298
|
export default AxiosHeaders;
|
package/lib/defaults/index.js
CHANGED
@@ -8,10 +8,6 @@ import toURLEncodedForm from '../helpers/toURLEncodedForm.js';
|
|
8
8
|
import platform from '../platform/index.js';
|
9
9
|
import formDataToJSON from '../helpers/formDataToJSON.js';
|
10
10
|
|
11
|
-
const DEFAULT_CONTENT_TYPE = {
|
12
|
-
'Content-Type': undefined
|
13
|
-
};
|
14
|
-
|
15
11
|
/**
|
16
12
|
* It takes a string, tries to parse it, and if it fails, it returns the stringified version
|
17
13
|
* of the input
|
@@ -150,17 +146,14 @@ const defaults = {
|
|
150
146
|
|
151
147
|
headers: {
|
152
148
|
common: {
|
153
|
-
'Accept': 'application/json, text/plain, */*'
|
149
|
+
'Accept': 'application/json, text/plain, */*',
|
150
|
+
'Content-Type': undefined
|
154
151
|
}
|
155
152
|
}
|
156
153
|
};
|
157
154
|
|
158
|
-
utils.forEach(['delete', 'get', 'head'],
|
155
|
+
utils.forEach(['delete', 'get', 'head', 'post', 'put', 'patch'], (method) => {
|
159
156
|
defaults.headers[method] = {};
|
160
157
|
});
|
161
158
|
|
162
|
-
utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
|
163
|
-
defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
|
164
|
-
});
|
165
|
-
|
166
159
|
export default defaults;
|
package/lib/env/data.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "1.
|
1
|
+
export const VERSION = "1.5.1";
|
package/lib/utils.js
CHANGED
@@ -540,8 +540,9 @@ const reduceDescriptors = (obj, reducer) => {
|
|
540
540
|
const reducedDescriptors = {};
|
541
541
|
|
542
542
|
forEach(descriptors, (descriptor, name) => {
|
543
|
-
|
544
|
-
|
543
|
+
let ret;
|
544
|
+
if ((ret = reducer(descriptor, name, obj)) !== false) {
|
545
|
+
reducedDescriptors[name] = ret || descriptor;
|
545
546
|
}
|
546
547
|
});
|
547
548
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "axios",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.5.1",
|
4
4
|
"description": "Promise based HTTP client for the browser and node.js",
|
5
5
|
"main": "index.js",
|
6
6
|
"exports": {
|
@@ -18,6 +18,8 @@
|
|
18
18
|
"default": "./index.js"
|
19
19
|
}
|
20
20
|
},
|
21
|
+
"./lib/adapters/http.js": "./lib/adapters/http.js",
|
22
|
+
"./lib/adapters/xhr.js": "./lib/adapters/xhr.js",
|
21
23
|
"./unsafe/*": "./lib/*",
|
22
24
|
"./unsafe/core/settle.js": "./lib/core/settle.js",
|
23
25
|
"./unsafe/core/buildFullPath.js": "./lib/core/buildFullPath.js",
|