2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-08 17:22:34 +03:00

Merge branch 'master' into cancel

This commit is contained in:
Nick Uraltsev
2016-09-15 21:09:29 -07:00
19 changed files with 357 additions and 49 deletions
+17 -4
View File
@@ -79,10 +79,23 @@ module.exports = function httpAdapter(config) {
auth: auth
};
if (config.proxy) {
options.host = config.proxy.host;
options.port = config.proxy.port;
options.path = parsed.protocol + '//' + parsed.hostname + options.path;
var proxy = config.proxy;
if (!proxy) {
var proxyEnv = parsed.protocol.slice(0, -1) + '_proxy';
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()];
if (proxyUrl) {
var parsedProxyUrl = url.parse(proxyUrl);
proxy = {
host: parsedProxyUrl.hostname,
port: parsedProxyUrl.port
};
}
}
if (proxy) {
options.host = proxy.host;
options.port = proxy.port;
options.path = parsed.protocol + '//' + parsed.hostname + (parsed.port ? ':' + parsed.port : '') + options.path;
}
var transport;
+11 -7
View File
@@ -55,7 +55,9 @@ module.exports = function xhrAdapter(config) {
// The request errored out and we didn't get a response, this will be
// handled by onerror instead
if (request.status === 0) {
// With one exception: request that using file: protocol, most browsers
// will return status as 0 even though it's a successful request
if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
return;
}
@@ -142,14 +144,16 @@ module.exports = function xhrAdapter(config) {
}
// Handle progress if needed
if (typeof config.progress === 'function') {
if (config.method === 'post' || config.method === 'put') {
request.upload.addEventListener('progress', config.progress);
} else if (config.method === 'get') {
request.addEventListener('progress', config.progress);
}
if (typeof config.onDownloadProgress === 'function') {
request.addEventListener('progress', config.onDownloadProgress);
}
// Not all browsers support upload events
if (typeof config.onUploadProgress === 'function' && request.upload) {
request.upload.addEventListener('progress', config.onUploadProgress);
}
if (requestData === undefined) {
requestData = null;
}
+1 -1
View File
@@ -217,7 +217,7 @@ function forEach(obj, fn) {
} else {
// Iterate over object keys
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
fn.call(null, obj[key], key, obj);
}
}