mirror of
https://github.com/tenrok/axios.git
synced 2026-06-23 20:40:40 +03:00
Merging master
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
var utils = require('./../utils');
|
var utils = require('./../utils');
|
||||||
var transformData = require('./transformData');
|
var transformData = require('./transformData');
|
||||||
var Cancel = require('../cancel/Cancel');
|
var Cancel = require('../cancel/Cancel');
|
||||||
|
var defaults = require('../defaults');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws a `Cancel` if cancellation has been requested.
|
* Throws a `Cancel` if cancellation has been requested.
|
||||||
@@ -14,8 +15,7 @@ function throwIfCancellationRequested(config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch a request to the server using whichever adapter
|
* Dispatch a request to the server using the configured adapter.
|
||||||
* is supported by the current environment.
|
|
||||||
*
|
*
|
||||||
* @param {object} config The config that is to be used for the request
|
* @param {object} config The config that is to be used for the request
|
||||||
* @returns {Promise} The Promise to be fulfilled
|
* @returns {Promise} The Promise to be fulfilled
|
||||||
@@ -47,23 +47,9 @@ module.exports = function dispatchRequest(config) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var adapter;
|
var adapter = config.adapter || defaults.adapter;
|
||||||
|
|
||||||
if (typeof config.adapter === 'function') {
|
return adapter(config).then(function onAdapterResolution(response) {
|
||||||
// For custom adapter support
|
|
||||||
adapter = config.adapter;
|
|
||||||
} else if (typeof XMLHttpRequest !== 'undefined') {
|
|
||||||
// For browsers use XHR adapter
|
|
||||||
adapter = require('../adapters/xhr');
|
|
||||||
} else if (typeof process !== 'undefined') {
|
|
||||||
// For node use HTTP adapter
|
|
||||||
adapter = require('../adapters/http');
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.resolve(config)
|
|
||||||
// Wrap synchronous adapter errors and pass configuration
|
|
||||||
.then(adapter)
|
|
||||||
.then(function onFulfilled(response) {
|
|
||||||
throwIfCancellationRequested(config);
|
throwIfCancellationRequested(config);
|
||||||
|
|
||||||
// Transform response data
|
// Transform response data
|
||||||
@@ -74,7 +60,7 @@ module.exports = function dispatchRequest(config) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}, function onRejected(reason) {
|
}, function onAdapterRejection(reason) {
|
||||||
if (!(reason instanceof Cancel)) {
|
if (!(reason instanceof Cancel)) {
|
||||||
throwIfCancellationRequested(config);
|
throwIfCancellationRequested(config);
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,21 @@ function setContentTypeIfUnset(headers, value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDefaultAdapter() {
|
||||||
|
var adapter;
|
||||||
|
if (typeof XMLHttpRequest !== 'undefined') {
|
||||||
|
// For browsers use XHR adapter
|
||||||
|
adapter = require('./adapters/xhr');
|
||||||
|
} else if (typeof process !== 'undefined') {
|
||||||
|
// For node use HTTP adapter
|
||||||
|
adapter = require('./adapters/http');
|
||||||
|
}
|
||||||
|
return adapter;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
adapter: getDefaultAdapter(),
|
||||||
|
|
||||||
transformRequest: [function transformRequest(data, headers) {
|
transformRequest: [function transformRequest(data, headers) {
|
||||||
normalizeHeaderName(headers, 'Content-Type');
|
normalizeHeaderName(headers, 'Content-Type');
|
||||||
if (utils.isFormData(data) ||
|
if (utils.isFormData(data) ||
|
||||||
|
|||||||
Reference in New Issue
Block a user