Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions lib/core/mergeConfig.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';
"use strict";

import utils from '../utils.js';
import utils from "../utils.js";
import AxiosHeaders from "./AxiosHeaders.js";

const headersToObject = (thing) => thing instanceof AxiosHeaders ? { ...thing } : thing;
const headersToObject = (thing) =>
thing instanceof AxiosHeaders ? { ...thing } : thing;

/**
* Config-specific merge-function which creates a new config-object
Expand Down Expand Up @@ -92,14 +93,27 @@ export default function mergeConfig(config1, config2) {
socketPath: defaultToConfig2,
responseEncoding: defaultToConfig2,
validateStatus: mergeDirectKeys,
headers: (a, b, prop) => mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true)
headers: (a, b, prop) =>
mergeDeepProperties(headersToObject(a), headersToObject(b), prop, true),
};

utils.forEach(Object.keys({ ...config1, ...config2 }), function computeConfigValue(prop) {
const merge = mergeMap[prop] || mergeDeepProperties;
const configValue = merge(config1[prop], config2[prop], prop);
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) || (config[prop] = configValue);
});
utils.forEach(
Object.keys({ ...config1, ...config2 }),
function computeConfigValue(prop) {
if (
prop === "__proto__" ||
prop === "constructor" ||
prop === "prototype"
)
return;
const merge = utils.hasOwnProp(mergeMap, prop)
? mergeMap[prop]
: mergeDeepProperties;
const configValue = merge(config1[prop], config2[prop], prop);
(utils.isUndefined(configValue) && merge !== mergeDirectKeys) ||
(config[prop] = configValue);
},
);

return config;
}
Loading
Loading