axios 1.1.3 → 1.2.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 +139 -74
- package/{UPGRADE_GUIDE.md → MIGRATION_GUIDE.md} +1 -1
- package/README.md +59 -22
- package/dist/axios.js +754 -576
- 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 +3054 -0
- package/dist/browser/axios.cjs.map +1 -0
- package/dist/esm/axios.js +719 -595
- 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 +618 -517
- package/dist/node/axios.cjs.map +1 -1
- package/index.d.cts +490 -0
- package/index.d.ts +33 -11
- package/index.js +8 -3
- package/karma.conf.cjs +1 -1
- package/lib/adapters/adapters.js +59 -0
- package/lib/adapters/http.js +23 -21
- package/lib/adapters/xhr.js +5 -2
- package/lib/axios.js +7 -3
- package/lib/core/Axios.js +10 -8
- package/lib/core/AxiosError.js +1 -1
- package/lib/core/AxiosHeaders.js +82 -76
- package/lib/core/dispatchRequest.js +6 -1
- package/lib/core/mergeConfig.js +50 -46
- package/lib/defaults/index.js +2 -21
- package/lib/env/data.js +1 -1
- package/lib/utils.js +68 -8
- package/package.json +14 -7
- package/rollup.config.js +37 -10
- package/tsconfig.json +2 -7
- package/tslint.json +6 -1
- package/lib/adapters/index.js +0 -33
package/lib/adapters/http.js
CHANGED
@@ -100,8 +100,10 @@ function setProxy(options, configProxy, location) {
|
|
100
100
|
};
|
101
101
|
}
|
102
102
|
|
103
|
+
const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(process) === 'process';
|
104
|
+
|
103
105
|
/*eslint consistent-return:0*/
|
104
|
-
export default function httpAdapter(config) {
|
106
|
+
export default isHttpAdapterSupported && function httpAdapter(config) {
|
105
107
|
return new Promise(function dispatchHttpRequest(resolvePromise, rejectPromise) {
|
106
108
|
let data = config.data;
|
107
109
|
const responseType = config.responseType;
|
@@ -203,7 +205,7 @@ export default function httpAdapter(config) {
|
|
203
205
|
data: convertedData,
|
204
206
|
status: 200,
|
205
207
|
statusText: 'OK',
|
206
|
-
headers:
|
208
|
+
headers: new AxiosHeaders(),
|
207
209
|
config
|
208
210
|
});
|
209
211
|
}
|
@@ -373,6 +375,23 @@ export default function httpAdapter(config) {
|
|
373
375
|
|
374
376
|
const streams = [res];
|
375
377
|
|
378
|
+
const responseLength = +res.headers['content-length'];
|
379
|
+
|
380
|
+
if (onDownloadProgress) {
|
381
|
+
const transformStream = new AxiosTransformStream({
|
382
|
+
length: utils.toFiniteNumber(responseLength),
|
383
|
+
maxRate: utils.toFiniteNumber(maxDownloadRate)
|
384
|
+
});
|
385
|
+
|
386
|
+
onDownloadProgress && transformStream.on('progress', progress => {
|
387
|
+
onDownloadProgress(Object.assign(progress, {
|
388
|
+
download: true
|
389
|
+
}));
|
390
|
+
});
|
391
|
+
|
392
|
+
streams.push(transformStream);
|
393
|
+
}
|
394
|
+
|
376
395
|
// uncompress the response body transparently if required
|
377
396
|
let responseStream = res;
|
378
397
|
|
@@ -383,7 +402,7 @@ export default function httpAdapter(config) {
|
|
383
402
|
if (config.decompress !== false) {
|
384
403
|
// if no content, but headers still say that it is encoded,
|
385
404
|
// remove the header not confuse downstream operations
|
386
|
-
if (
|
405
|
+
if ((!responseLength || res.statusCode === 204) && res.headers['content-encoding']) {
|
387
406
|
delete res.headers['content-encoding'];
|
388
407
|
}
|
389
408
|
|
@@ -406,23 +425,6 @@ export default function httpAdapter(config) {
|
|
406
425
|
}
|
407
426
|
}
|
408
427
|
|
409
|
-
if (onDownloadProgress) {
|
410
|
-
const responseLength = +res.headers['content-length'];
|
411
|
-
|
412
|
-
const transformStream = new AxiosTransformStream({
|
413
|
-
length: utils.toFiniteNumber(responseLength),
|
414
|
-
maxRate: utils.toFiniteNumber(maxDownloadRate)
|
415
|
-
});
|
416
|
-
|
417
|
-
onDownloadProgress && transformStream.on('progress', progress => {
|
418
|
-
onDownloadProgress(Object.assign(progress, {
|
419
|
-
download: true
|
420
|
-
}));
|
421
|
-
});
|
422
|
-
|
423
|
-
streams.push(transformStream);
|
424
|
-
}
|
425
|
-
|
426
428
|
responseStream = streams.length > 1 ? stream.pipeline(streams, utils.noop) : streams[0];
|
427
429
|
|
428
430
|
const offListeners = stream.finished(responseStream, () => {
|
@@ -588,4 +590,4 @@ export default function httpAdapter(config) {
|
|
588
590
|
});
|
589
591
|
}
|
590
592
|
|
591
|
-
export const __setProxy = setProxy;
|
593
|
+
export const __setProxy = setProxy;
|
package/lib/adapters/xhr.js
CHANGED
@@ -33,7 +33,8 @@ function progressEventReducer(listener, isDownloadStream) {
|
|
33
33
|
progress: total ? (loaded / total) : undefined,
|
34
34
|
bytes: progressBytes,
|
35
35
|
rate: rate ? rate : undefined,
|
36
|
-
estimated: rate && total && inRange ? (total - loaded) / rate : undefined
|
36
|
+
estimated: rate && total && inRange ? (total - loaded) / rate : undefined,
|
37
|
+
event: e
|
37
38
|
};
|
38
39
|
|
39
40
|
data[isDownloadStream ? 'download' : 'upload'] = true;
|
@@ -42,7 +43,9 @@ function progressEventReducer(listener, isDownloadStream) {
|
|
42
43
|
};
|
43
44
|
}
|
44
45
|
|
45
|
-
|
46
|
+
const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
|
47
|
+
|
48
|
+
export default isXHRAdapterSupported && function (config) {
|
46
49
|
return new Promise(function dispatchXhrRequest(resolve, reject) {
|
47
50
|
let requestData = config.data;
|
48
51
|
const requestHeaders = AxiosHeaders.from(config.headers).normalize();
|
package/lib/axios.js
CHANGED
@@ -14,6 +14,7 @@ import toFormData from './helpers/toFormData.js';
|
|
14
14
|
import AxiosError from './core/AxiosError.js';
|
15
15
|
import spread from './helpers/spread.js';
|
16
16
|
import isAxiosError from './helpers/isAxiosError.js';
|
17
|
+
import AxiosHeaders from "./core/AxiosHeaders.js";
|
17
18
|
|
18
19
|
/**
|
19
20
|
* Create an instance of Axios
|
@@ -69,8 +70,11 @@ axios.spread = spread;
|
|
69
70
|
// Expose isAxiosError
|
70
71
|
axios.isAxiosError = isAxiosError;
|
71
72
|
|
72
|
-
axios.
|
73
|
-
|
74
|
-
|
73
|
+
axios.AxiosHeaders = AxiosHeaders;
|
74
|
+
|
75
|
+
axios.formToJSON = thing => formDataToJSON(utils.isHTMLForm(thing) ? new FormData(thing) : thing);
|
76
|
+
|
77
|
+
axios.default = axios;
|
75
78
|
|
79
|
+
// this module should only have a default export
|
76
80
|
export default axios
|
package/lib/core/Axios.js
CHANGED
@@ -47,7 +47,7 @@ class Axios {
|
|
47
47
|
|
48
48
|
config = mergeConfig(this.defaults, config);
|
49
49
|
|
50
|
-
const {transitional, paramsSerializer} = config;
|
50
|
+
const {transitional, paramsSerializer, headers} = config;
|
51
51
|
|
52
52
|
if (transitional !== undefined) {
|
53
53
|
validator.assertOptions(transitional, {
|
@@ -67,20 +67,22 @@ class Axios {
|
|
67
67
|
// Set config.method
|
68
68
|
config.method = (config.method || this.defaults.method || 'get').toLowerCase();
|
69
69
|
|
70
|
+
let contextHeaders;
|
71
|
+
|
70
72
|
// Flatten headers
|
71
|
-
|
72
|
-
|
73
|
-
|
73
|
+
contextHeaders = headers && utils.merge(
|
74
|
+
headers.common,
|
75
|
+
headers[config.method]
|
74
76
|
);
|
75
77
|
|
76
|
-
|
78
|
+
contextHeaders && utils.forEach(
|
77
79
|
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
78
|
-
|
79
|
-
delete
|
80
|
+
(method) => {
|
81
|
+
delete headers[method];
|
80
82
|
}
|
81
83
|
);
|
82
84
|
|
83
|
-
config.headers =
|
85
|
+
config.headers = AxiosHeaders.concat(contextHeaders, headers);
|
84
86
|
|
85
87
|
// filter out skipped interceptors
|
86
88
|
const requestInterceptorChain = [];
|
package/lib/core/AxiosError.js
CHANGED
@@ -45,7 +45,7 @@ utils.inherits(AxiosError, Error, {
|
|
45
45
|
columnNumber: this.columnNumber,
|
46
46
|
stack: this.stack,
|
47
47
|
// Axios
|
48
|
-
config: this.config,
|
48
|
+
config: utils.toJSONObject(this.config),
|
49
49
|
code: this.code,
|
50
50
|
status: this.response && this.response.status ? this.response.status : null
|
51
51
|
};
|
package/lib/core/AxiosHeaders.js
CHANGED
@@ -4,7 +4,6 @@ import utils from '../utils.js';
|
|
4
4
|
import parseHeaders from '../helpers/parseHeaders.js';
|
5
5
|
|
6
6
|
const $internals = Symbol('internals');
|
7
|
-
const $defaults = Symbol('defaults');
|
8
7
|
|
9
8
|
function normalizeHeader(header) {
|
10
9
|
return header && String(header).trim().toLowerCase();
|
@@ -30,6 +29,10 @@ function parseTokens(str) {
|
|
30
29
|
return tokens;
|
31
30
|
}
|
32
31
|
|
32
|
+
function isValidHeaderName(str) {
|
33
|
+
return /^[-_a-zA-Z]+$/.test(str.trim());
|
34
|
+
}
|
35
|
+
|
33
36
|
function matchHeaderValue(context, value, header, filter) {
|
34
37
|
if (utils.isFunction(filter)) {
|
35
38
|
return filter.call(this, value, header);
|
@@ -66,27 +69,12 @@ function buildAccessors(obj, header) {
|
|
66
69
|
});
|
67
70
|
}
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
let i = keys.length;
|
73
|
-
let _key;
|
74
|
-
while (i-- > 0) {
|
75
|
-
_key = keys[i];
|
76
|
-
if (key === _key.toLowerCase()) {
|
77
|
-
return _key;
|
78
|
-
}
|
72
|
+
class AxiosHeaders {
|
73
|
+
constructor(headers) {
|
74
|
+
headers && this.set(headers);
|
79
75
|
}
|
80
|
-
return null;
|
81
|
-
}
|
82
|
-
|
83
|
-
function AxiosHeaders(headers, defaults) {
|
84
|
-
headers && this.set(headers);
|
85
|
-
this[$defaults] = defaults || null;
|
86
|
-
}
|
87
76
|
|
88
|
-
|
89
|
-
set: function(header, valueOrRewrite, rewrite) {
|
77
|
+
set(header, valueOrRewrite, rewrite) {
|
90
78
|
const self = this;
|
91
79
|
|
92
80
|
function setHeader(_value, _header, _rewrite) {
|
@@ -96,69 +84,70 @@ Object.assign(AxiosHeaders.prototype, {
|
|
96
84
|
throw new Error('header name must be a non-empty string');
|
97
85
|
}
|
98
86
|
|
99
|
-
const key = findKey(self, lHeader);
|
87
|
+
const key = utils.findKey(self, lHeader);
|
100
88
|
|
101
|
-
if
|
102
|
-
|
89
|
+
if(!key || self[key] === undefined || _rewrite === true || (_rewrite === undefined && self[key] !== false)) {
|
90
|
+
self[key || _header] = normalizeValue(_value);
|
103
91
|
}
|
104
|
-
|
105
|
-
self[key || _header] = normalizeValue(_value);
|
106
92
|
}
|
107
93
|
|
108
|
-
|
109
|
-
utils.forEach(
|
110
|
-
|
111
|
-
|
94
|
+
const setHeaders = (headers, _rewrite) =>
|
95
|
+
utils.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
|
96
|
+
|
97
|
+
if (utils.isPlainObject(header) || header instanceof this.constructor) {
|
98
|
+
setHeaders(header, valueOrRewrite)
|
99
|
+
} else if(utils.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
|
100
|
+
setHeaders(parseHeaders(header), valueOrRewrite);
|
112
101
|
} else {
|
113
|
-
setHeader(valueOrRewrite, header, rewrite);
|
102
|
+
header != null && setHeader(valueOrRewrite, header, rewrite);
|
114
103
|
}
|
115
104
|
|
116
105
|
return this;
|
117
|
-
}
|
106
|
+
}
|
118
107
|
|
119
|
-
get
|
108
|
+
get(header, parser) {
|
120
109
|
header = normalizeHeader(header);
|
121
110
|
|
122
|
-
if (
|
111
|
+
if (header) {
|
112
|
+
const key = utils.findKey(this, header);
|
123
113
|
|
124
|
-
|
114
|
+
if (key) {
|
115
|
+
const value = this[key];
|
125
116
|
|
126
|
-
|
127
|
-
|
117
|
+
if (!parser) {
|
118
|
+
return value;
|
119
|
+
}
|
128
120
|
|
129
|
-
|
130
|
-
|
131
|
-
|
121
|
+
if (parser === true) {
|
122
|
+
return parseTokens(value);
|
123
|
+
}
|
132
124
|
|
133
|
-
|
134
|
-
|
135
|
-
|
125
|
+
if (utils.isFunction(parser)) {
|
126
|
+
return parser.call(this, value, key);
|
127
|
+
}
|
136
128
|
|
137
|
-
|
138
|
-
|
139
|
-
|
129
|
+
if (utils.isRegExp(parser)) {
|
130
|
+
return parser.exec(value);
|
131
|
+
}
|
140
132
|
|
141
|
-
|
142
|
-
return parser.exec(value);
|
133
|
+
throw new TypeError('parser must be boolean|regexp|function');
|
143
134
|
}
|
144
|
-
|
145
|
-
throw new TypeError('parser must be boolean|regexp|function');
|
146
135
|
}
|
147
|
-
}
|
136
|
+
}
|
148
137
|
|
149
|
-
has
|
138
|
+
has(header, matcher) {
|
150
139
|
header = normalizeHeader(header);
|
151
140
|
|
152
141
|
if (header) {
|
153
|
-
const key = findKey(this, header);
|
142
|
+
const key = utils.findKey(this, header);
|
154
143
|
|
155
144
|
return !!(key && (!matcher || matchHeaderValue(this, this[key], key, matcher)));
|
156
145
|
}
|
157
146
|
|
158
147
|
return false;
|
159
|
-
}
|
148
|
+
}
|
160
149
|
|
161
|
-
delete
|
150
|
+
delete(header, matcher) {
|
162
151
|
const self = this;
|
163
152
|
let deleted = false;
|
164
153
|
|
@@ -166,7 +155,7 @@ Object.assign(AxiosHeaders.prototype, {
|
|
166
155
|
_header = normalizeHeader(_header);
|
167
156
|
|
168
157
|
if (_header) {
|
169
|
-
const key = findKey(self, _header);
|
158
|
+
const key = utils.findKey(self, _header);
|
170
159
|
|
171
160
|
if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
|
172
161
|
delete self[key];
|
@@ -183,18 +172,18 @@ Object.assign(AxiosHeaders.prototype, {
|
|
183
172
|
}
|
184
173
|
|
185
174
|
return deleted;
|
186
|
-
}
|
175
|
+
}
|
187
176
|
|
188
|
-
clear
|
177
|
+
clear() {
|
189
178
|
return Object.keys(this).forEach(this.delete.bind(this));
|
190
|
-
}
|
179
|
+
}
|
191
180
|
|
192
|
-
normalize
|
181
|
+
normalize(format) {
|
193
182
|
const self = this;
|
194
183
|
const headers = {};
|
195
184
|
|
196
185
|
utils.forEach(this, (value, header) => {
|
197
|
-
const key = findKey(headers, header);
|
186
|
+
const key = utils.findKey(headers, header);
|
198
187
|
|
199
188
|
if (key) {
|
200
189
|
self[key] = normalizeValue(value);
|
@@ -214,30 +203,47 @@ Object.assign(AxiosHeaders.prototype, {
|
|
214
203
|
});
|
215
204
|
|
216
205
|
return this;
|
217
|
-
}
|
206
|
+
}
|
207
|
+
|
208
|
+
concat(...targets) {
|
209
|
+
return this.constructor.concat(this, ...targets);
|
210
|
+
}
|
218
211
|
|
219
|
-
toJSON
|
212
|
+
toJSON(asStrings) {
|
220
213
|
const obj = Object.create(null);
|
221
214
|
|
222
|
-
utils.forEach(
|
223
|
-
(value,
|
224
|
-
|
225
|
-
obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value;
|
226
|
-
});
|
215
|
+
utils.forEach(this, (value, header) => {
|
216
|
+
value != null && value !== false && (obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value);
|
217
|
+
});
|
227
218
|
|
228
219
|
return obj;
|
229
220
|
}
|
230
|
-
});
|
231
221
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
222
|
+
[Symbol.iterator]() {
|
223
|
+
return Object.entries(this.toJSON())[Symbol.iterator]();
|
224
|
+
}
|
225
|
+
|
226
|
+
toString() {
|
227
|
+
return Object.entries(this.toJSON()).map(([header, value]) => header + ': ' + value).join('\n');
|
228
|
+
}
|
229
|
+
|
230
|
+
get [Symbol.toStringTag]() {
|
231
|
+
return 'AxiosHeaders';
|
232
|
+
}
|
233
|
+
|
234
|
+
static from(thing) {
|
237
235
|
return thing instanceof this ? thing : new this(thing);
|
238
|
-
}
|
236
|
+
}
|
239
237
|
|
240
|
-
|
238
|
+
static concat(first, ...targets) {
|
239
|
+
const computed = new this(first);
|
240
|
+
|
241
|
+
targets.forEach((target) => computed.set(target));
|
242
|
+
|
243
|
+
return computed;
|
244
|
+
}
|
245
|
+
|
246
|
+
static accessor(header) {
|
241
247
|
const internals = this[$internals] = (this[$internals] = {
|
242
248
|
accessors: {}
|
243
249
|
});
|
@@ -258,7 +264,7 @@ Object.assign(AxiosHeaders, {
|
|
258
264
|
|
259
265
|
return this;
|
260
266
|
}
|
261
|
-
}
|
267
|
+
}
|
262
268
|
|
263
269
|
AxiosHeaders.accessor(['Content-Type', 'Content-Length', 'Accept', 'Accept-Encoding', 'User-Agent']);
|
264
270
|
|
@@ -5,6 +5,7 @@ import isCancel from '../cancel/isCancel.js';
|
|
5
5
|
import defaults from '../defaults/index.js';
|
6
6
|
import CanceledError from '../cancel/CanceledError.js';
|
7
7
|
import AxiosHeaders from '../core/AxiosHeaders.js';
|
8
|
+
import adapters from "../adapters/adapters.js";
|
8
9
|
|
9
10
|
/**
|
10
11
|
* Throws a `CanceledError` if cancellation has been requested.
|
@@ -41,7 +42,11 @@ export default function dispatchRequest(config) {
|
|
41
42
|
config.transformRequest
|
42
43
|
);
|
43
44
|
|
44
|
-
|
45
|
+
if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
|
46
|
+
config.headers.setContentType('application/x-www-form-urlencoded', false);
|
47
|
+
}
|
48
|
+
|
49
|
+
const adapter = adapters.getAdapter(config.adapter || defaults.adapter);
|
45
50
|
|
46
51
|
return adapter(config).then(function onAdapterResolution(response) {
|
47
52
|
throwIfCancellationRequested(config);
|
package/lib/core/mergeConfig.js
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
import utils from '../utils.js';
|
4
|
+
import AxiosHeaders from "./AxiosHeaders.js";
|
5
|
+
|
6
|
+
const headersToObject = (thing) => thing instanceof AxiosHeaders ? thing.toJSON() : thing;
|
4
7
|
|
5
8
|
/**
|
6
9
|
* Config-specific merge-function which creates a new config-object
|
@@ -16,9 +19,9 @@ export default function mergeConfig(config1, config2) {
|
|
16
19
|
config2 = config2 || {};
|
17
20
|
const config = {};
|
18
21
|
|
19
|
-
function getMergedValue(target, source) {
|
22
|
+
function getMergedValue(target, source, caseless) {
|
20
23
|
if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
|
21
|
-
return utils.merge(target, source);
|
24
|
+
return utils.merge.call({caseless}, target, source);
|
22
25
|
} else if (utils.isPlainObject(source)) {
|
23
26
|
return utils.merge({}, source);
|
24
27
|
} else if (utils.isArray(source)) {
|
@@ -28,72 +31,73 @@ export default function mergeConfig(config1, config2) {
|
|
28
31
|
}
|
29
32
|
|
30
33
|
// eslint-disable-next-line consistent-return
|
31
|
-
function mergeDeepProperties(
|
32
|
-
if (!utils.isUndefined(
|
33
|
-
return getMergedValue(
|
34
|
-
} else if (!utils.isUndefined(
|
35
|
-
return getMergedValue(undefined,
|
34
|
+
function mergeDeepProperties(a, b, caseless) {
|
35
|
+
if (!utils.isUndefined(b)) {
|
36
|
+
return getMergedValue(a, b, caseless);
|
37
|
+
} else if (!utils.isUndefined(a)) {
|
38
|
+
return getMergedValue(undefined, a, caseless);
|
36
39
|
}
|
37
40
|
}
|
38
41
|
|
39
42
|
// eslint-disable-next-line consistent-return
|
40
|
-
function valueFromConfig2(
|
41
|
-
if (!utils.isUndefined(
|
42
|
-
return getMergedValue(undefined,
|
43
|
+
function valueFromConfig2(a, b) {
|
44
|
+
if (!utils.isUndefined(b)) {
|
45
|
+
return getMergedValue(undefined, b);
|
43
46
|
}
|
44
47
|
}
|
45
48
|
|
46
49
|
// eslint-disable-next-line consistent-return
|
47
|
-
function defaultToConfig2(
|
48
|
-
if (!utils.isUndefined(
|
49
|
-
return getMergedValue(undefined,
|
50
|
-
} else if (!utils.isUndefined(
|
51
|
-
return getMergedValue(undefined,
|
50
|
+
function defaultToConfig2(a, b) {
|
51
|
+
if (!utils.isUndefined(b)) {
|
52
|
+
return getMergedValue(undefined, b);
|
53
|
+
} else if (!utils.isUndefined(a)) {
|
54
|
+
return getMergedValue(undefined, a);
|
52
55
|
}
|
53
56
|
}
|
54
57
|
|
55
58
|
// eslint-disable-next-line consistent-return
|
56
|
-
function mergeDirectKeys(prop) {
|
59
|
+
function mergeDirectKeys(a, b, prop) {
|
57
60
|
if (prop in config2) {
|
58
|
-
return getMergedValue(
|
61
|
+
return getMergedValue(a, b);
|
59
62
|
} else if (prop in config1) {
|
60
|
-
return getMergedValue(undefined,
|
63
|
+
return getMergedValue(undefined, a);
|
61
64
|
}
|
62
65
|
}
|
63
66
|
|
64
67
|
const mergeMap = {
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
68
|
+
url: valueFromConfig2,
|
69
|
+
method: valueFromConfig2,
|
70
|
+
data: valueFromConfig2,
|
71
|
+
baseURL: defaultToConfig2,
|
72
|
+
transformRequest: defaultToConfig2,
|
73
|
+
transformResponse: defaultToConfig2,
|
74
|
+
paramsSerializer: defaultToConfig2,
|
75
|
+
timeout: defaultToConfig2,
|
76
|
+
timeoutMessage: defaultToConfig2,
|
77
|
+
withCredentials: defaultToConfig2,
|
78
|
+
adapter: defaultToConfig2,
|
79
|
+
responseType: defaultToConfig2,
|
80
|
+
xsrfCookieName: defaultToConfig2,
|
81
|
+
xsrfHeaderName: defaultToConfig2,
|
82
|
+
onUploadProgress: defaultToConfig2,
|
83
|
+
onDownloadProgress: defaultToConfig2,
|
84
|
+
decompress: defaultToConfig2,
|
85
|
+
maxContentLength: defaultToConfig2,
|
86
|
+
maxBodyLength: defaultToConfig2,
|
87
|
+
beforeRedirect: defaultToConfig2,
|
88
|
+
transport: defaultToConfig2,
|
89
|
+
httpAgent: defaultToConfig2,
|
90
|
+
httpsAgent: defaultToConfig2,
|
91
|
+
cancelToken: defaultToConfig2,
|
92
|
+
socketPath: defaultToConfig2,
|
93
|
+
responseEncoding: defaultToConfig2,
|
94
|
+
validateStatus: mergeDirectKeys,
|
95
|
+
headers: (a, b) => mergeDeepProperties(headersToObject(a), headersToObject(b), true)
|
92
96
|
};
|
93
97
|
|
94
98
|
utils.forEach(Object.keys(config1).concat(Object.keys(config2)), function computeConfigValue(prop) {
|
95
99
|
const merge = mergeMap[prop] || mergeDeepProperties;
|
96
|
-
const configValue = merge(prop);
|
100
|
+
const configValue = merge(config1[prop], config2[prop], prop);
|
97
101
|
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
|
98
102
|
});
|
99
103
|
|
package/lib/defaults/index.js
CHANGED
@@ -7,30 +7,11 @@ import toFormData from '../helpers/toFormData.js';
|
|
7
7
|
import toURLEncodedForm from '../helpers/toURLEncodedForm.js';
|
8
8
|
import platform from '../platform/index.js';
|
9
9
|
import formDataToJSON from '../helpers/formDataToJSON.js';
|
10
|
-
import adapters from '../adapters/index.js';
|
11
10
|
|
12
11
|
const DEFAULT_CONTENT_TYPE = {
|
13
|
-
'Content-Type':
|
12
|
+
'Content-Type': undefined
|
14
13
|
};
|
15
14
|
|
16
|
-
/**
|
17
|
-
* If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
|
18
|
-
* adapter
|
19
|
-
*
|
20
|
-
* @returns {Function}
|
21
|
-
*/
|
22
|
-
function getDefaultAdapter() {
|
23
|
-
let adapter;
|
24
|
-
if (typeof XMLHttpRequest !== 'undefined') {
|
25
|
-
// For browsers use XHR adapter
|
26
|
-
adapter = adapters.getAdapter('xhr');
|
27
|
-
} else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
|
28
|
-
// For node use HTTP adapter
|
29
|
-
adapter = adapters.getAdapter('http');
|
30
|
-
}
|
31
|
-
return adapter;
|
32
|
-
}
|
33
|
-
|
34
15
|
/**
|
35
16
|
* It takes a string, tries to parse it, and if it fails, it returns the stringified version
|
36
17
|
* of the input
|
@@ -60,7 +41,7 @@ const defaults = {
|
|
60
41
|
|
61
42
|
transitional: transitionalDefaults,
|
62
43
|
|
63
|
-
adapter:
|
44
|
+
adapter: ['xhr', 'http'],
|
64
45
|
|
65
46
|
transformRequest: [function transformRequest(data, headers) {
|
66
47
|
const contentType = headers.getContentType() || '';
|
package/lib/env/data.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const VERSION = "1.
|
1
|
+
export const VERSION = "1.2.0";
|