mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
@@ -1,5 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
var utils = require('./../utils');
|
||||
var transformData = require('./transformData');
|
||||
|
||||
/**
|
||||
* Dispatch a request to the server using whichever adapter
|
||||
* is supported by the current environment.
|
||||
@@ -8,6 +11,30 @@
|
||||
* @returns {Promise} The Promise to be fulfilled
|
||||
*/
|
||||
module.exports = function dispatchRequest(config) {
|
||||
// Ensure headers exist
|
||||
config.headers = config.headers || {};
|
||||
|
||||
// Transform request data
|
||||
config.data = transformData(
|
||||
config.data,
|
||||
config.headers,
|
||||
config.transformRequest
|
||||
);
|
||||
|
||||
// Flatten headers
|
||||
config.headers = utils.merge(
|
||||
config.headers.common || {},
|
||||
config.headers[config.method] || {},
|
||||
config.headers || {}
|
||||
);
|
||||
|
||||
utils.forEach(
|
||||
['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
|
||||
function cleanHeaderConfig(method) {
|
||||
delete config.headers[method];
|
||||
}
|
||||
);
|
||||
|
||||
return new Promise(function executor(resolve, reject) {
|
||||
try {
|
||||
var adapter;
|
||||
|
||||
Reference in New Issue
Block a user