MCPcopy
hub / github.com/axios/axios / resolveConfig

Function resolveConfig

lib/helpers/resolveConfig.js:39–117  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

37 );
38
39function resolveConfig(config) {
40 const newConfig = mergeConfig({}, config);
41
42 // Read only own properties to prevent prototype pollution gadgets
43 // (e.g. Object.prototype.baseURL = 'https://evil.com').
44 const own = (key) => (utils.hasOwnProp(newConfig, key) ? newConfig[key] : undefined);
45
46 const data = own('data');
47 let withXSRFToken = own('withXSRFToken');
48 const xsrfHeaderName = own('xsrfHeaderName');
49 const xsrfCookieName = own('xsrfCookieName');
50 let headers = own('headers');
51 const auth = own('auth');
52 const baseURL = own('baseURL');
53 const allowAbsoluteUrls = own('allowAbsoluteUrls');
54 const url = own('url');
55
56 newConfig.headers = headers = AxiosHeaders.from(headers);
57
58 newConfig.url = buildURL(
59 buildFullPath(baseURL, url, allowAbsoluteUrls, newConfig),
60 own('params'),
61 own('paramsSerializer')
62 );
63
64 // HTTP basic authentication
65 if (auth) {
66 const username = utils.getSafeProp(auth, 'username') || '';
67 const password = utils.getSafeProp(auth, 'password') || '';
68
69 try {
70 headers.set(
71 'Authorization',
72 'Basic ' + btoa(username + ':' + (password ? encodeUTF8(password) : ''))
73 );
74 } catch (e) {
75 throw AxiosError.from(e, AxiosError.ERR_BAD_OPTION_VALUE, config);
76 }
77 }
78
79 if (utils.isFormData(data)) {
80 if (
81 platform.hasStandardBrowserEnv ||
82 platform.hasStandardBrowserWebWorkerEnv ||
83 utils.isReactNative(data)
84 ) {
85 headers.setContentType(undefined); // browser/web worker/RN handles it
86 } else if (utils.isFunction(data.getHeaders)) {
87 // Node.js FormData (like form-data package)
88 setFormDataHeaders(headers, data.getHeaders(), own('formDataHeaderPolicy'));
89 }
90 }
91
92 // Add xsrf header
93 // This is only done if running in a standard browser environment.
94 // Specifically not if we're in a web worker, or react-native.
95
96 if (platform.hasStandardBrowserEnv) {

Callers 5

factoryFunction · 0.85
xhr.jsFile · 0.85

Calls 9

mergeConfigFunction · 0.85
buildURLFunction · 0.85
buildFullPathFunction · 0.85
setMethod · 0.80
getHeadersMethod · 0.80
ownFunction · 0.70
encodeUTF8Function · 0.70
setFormDataHeadersFunction · 0.70
fromMethod · 0.45

Tested by

no test coverage detected