2
0
mirror of https://github.com/tenrok/axios.git synced 2026-05-24 14:04:14 +03:00

Resolving conflicts and modifying http adapter to not change status code error range

This commit is contained in:
Nick Uraltsev
2016-05-31 17:53:45 -07:00
2 changed files with 33 additions and 4 deletions
+14 -4
View File
@@ -3,8 +3,10 @@
var utils = require('./../utils');
var buildURL = require('./../helpers/buildURL');
var transformData = require('./../helpers/transformData');
var http = require('follow-redirects').http;
var https = require('follow-redirects').https;
var http = require('http');
var https = require('https');
var httpFollow = require('follow-redirects').http;
var httpsFollow = require('follow-redirects').https;
var url = require('url');
var zlib = require('zlib');
var pkg = require('./../../package.json');
@@ -70,8 +72,17 @@ module.exports = function httpAdapter(resolve, reject, config) {
options.path = parsed.protocol + '//' + parsed.hostname + options.path;
}
var transport;
if (config.maxRedirects === 0) {
transport = parsed.protocol === 'https:' ? https : http;
} else {
if (config.maxRedirects) {
options.maxRedirects = config.maxRedirects;
}
transport = parsed.protocol === 'https:' ? httpsFollow : httpFollow;
}
// Create the request
var transport = parsed.protocol === 'https:' ? https : http;
var req = transport.request(options, function handleResponse(res) {
if (aborted) return;
@@ -101,7 +112,6 @@ module.exports = function httpAdapter(resolve, reject, config) {
config: config,
request: req
};
if (config.responseType === 'stream') {
response.data = stream;
settle(resolve, reject, response);
+19
View File
@@ -79,6 +79,25 @@ module.exports = {
});
},
testNoRedirect: function (test) {
server = http.createServer(function (req, res) {
res.setHeader('Location', '/foo');
res.statusCode = 302;
res.end();
}).listen(4444, function () {
axios.get('http://localhost:4444/', {
maxRedirects: 0,
validateStatus: function () {
return true;
}
}).then(function (res) {
test.equal(res.status, 302);
test.equal(res.headers['location'], '/foo');
test.done();
});
});
},
testTransparentGunzip: function (test) {
var data = {
firstName: 'Fred',