2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-05 16:42:32 +03:00

Refactored adapters loader; (#5277)

Co-authored-by: Jay <jasonsaayman@gmail.com>
This commit is contained in:
Dmitriy Mozgovoy
2022-11-22 20:53:56 +02:00
committed by GitHub
parent a3d901777b
commit d032edda08
9 changed files with 89 additions and 59 deletions
+1 -20
View File
@@ -7,30 +7,11 @@ import toFormData from '../helpers/toFormData.js';
import toURLEncodedForm from '../helpers/toURLEncodedForm.js';
import platform from '../platform/index.js';
import formDataToJSON from '../helpers/formDataToJSON.js';
import adapters from '../adapters/index.js';
const DEFAULT_CONTENT_TYPE = {
'Content-Type': undefined
};
/**
* If the browser has an XMLHttpRequest object, use the XHR adapter, otherwise use the HTTP
* adapter
*
* @returns {Function}
*/
function getDefaultAdapter() {
let adapter;
if (typeof XMLHttpRequest !== 'undefined') {
// For browsers use XHR adapter
adapter = adapters.getAdapter('xhr');
} else if (typeof process !== 'undefined' && utils.kindOf(process) === 'process') {
// For node use HTTP adapter
adapter = adapters.getAdapter('http');
}
return adapter;
}
/**
* It takes a string, tries to parse it, and if it fails, it returns the stringified version
* of the input
@@ -60,7 +41,7 @@ const defaults = {
transitional: transitionalDefaults,
adapter: getDefaultAdapter(),
adapter: ['xhr', 'http'],
transformRequest: [function transformRequest(data, headers) {
const contentType = headers.getContentType() || '';