source: imaps-frontend/node_modules/axios/lib/helpers/resolveConfig.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.0 KB
Line 
1import platform from "../platform/index.js";
2import utils from "../utils.js";
3import isURLSameOrigin from "./isURLSameOrigin.js";
4import cookies from "./cookies.js";
5import buildFullPath from "../core/buildFullPath.js";
6import mergeConfig from "../core/mergeConfig.js";
7import AxiosHeaders from "../core/AxiosHeaders.js";
8import buildURL from "./buildURL.js";
9
10export default (config) => {
11 const newConfig = mergeConfig({}, config);
12
13 let {data, withXSRFToken, xsrfHeaderName, xsrfCookieName, headers, auth} = newConfig;
14
15 newConfig.headers = headers = AxiosHeaders.from(headers);
16
17 newConfig.url = buildURL(buildFullPath(newConfig.baseURL, newConfig.url), config.params, config.paramsSerializer);
18
19 // HTTP basic authentication
20 if (auth) {
21 headers.set('Authorization', 'Basic ' +
22 btoa((auth.username || '') + ':' + (auth.password ? unescape(encodeURIComponent(auth.password)) : ''))
23 );
24 }
25
26 let contentType;
27
28 if (utils.isFormData(data)) {
29 if (platform.hasStandardBrowserEnv || platform.hasStandardBrowserWebWorkerEnv) {
30 headers.setContentType(undefined); // Let the browser set it
31 } else if ((contentType = headers.getContentType()) !== false) {
32 // fix semicolon duplication issue for ReactNative FormData implementation
33 const [type, ...tokens] = contentType ? contentType.split(';').map(token => token.trim()).filter(Boolean) : [];
34 headers.setContentType([type || 'multipart/form-data', ...tokens].join('; '));
35 }
36 }
37
38 // Add xsrf header
39 // This is only done if running in a standard browser environment.
40 // Specifically not if we're in a web worker, or react-native.
41
42 if (platform.hasStandardBrowserEnv) {
43 withXSRFToken && utils.isFunction(withXSRFToken) && (withXSRFToken = withXSRFToken(newConfig));
44
45 if (withXSRFToken || (withXSRFToken !== false && isURLSameOrigin(newConfig.url))) {
46 // Add xsrf header
47 const xsrfValue = xsrfHeaderName && xsrfCookieName && cookies.read(xsrfCookieName);
48
49 if (xsrfValue) {
50 headers.set(xsrfHeaderName, xsrfValue);
51 }
52 }
53 }
54
55 return newConfig;
56}
57
Note: See TracBrowser for help on using the repository browser.