mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
Resolving conflicts and modifying http adapter to not change status code error range
This commit is contained in:
+14
-4
@@ -3,8 +3,10 @@
|
|||||||
var utils = require('./../utils');
|
var utils = require('./../utils');
|
||||||
var buildURL = require('./../helpers/buildURL');
|
var buildURL = require('./../helpers/buildURL');
|
||||||
var transformData = require('./../helpers/transformData');
|
var transformData = require('./../helpers/transformData');
|
||||||
var http = require('follow-redirects').http;
|
var http = require('http');
|
||||||
var https = require('follow-redirects').https;
|
var https = require('https');
|
||||||
|
var httpFollow = require('follow-redirects').http;
|
||||||
|
var httpsFollow = require('follow-redirects').https;
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
var zlib = require('zlib');
|
var zlib = require('zlib');
|
||||||
var pkg = require('./../../package.json');
|
var pkg = require('./../../package.json');
|
||||||
@@ -70,8 +72,17 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
|||||||
options.path = parsed.protocol + '//' + parsed.hostname + options.path;
|
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
|
// Create the request
|
||||||
var transport = parsed.protocol === 'https:' ? https : http;
|
|
||||||
var req = transport.request(options, function handleResponse(res) {
|
var req = transport.request(options, function handleResponse(res) {
|
||||||
if (aborted) return;
|
if (aborted) return;
|
||||||
|
|
||||||
@@ -101,7 +112,6 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
|||||||
config: config,
|
config: config,
|
||||||
request: req
|
request: req
|
||||||
};
|
};
|
||||||
|
|
||||||
if (config.responseType === 'stream') {
|
if (config.responseType === 'stream') {
|
||||||
response.data = stream;
|
response.data = stream;
|
||||||
settle(resolve, reject, response);
|
settle(resolve, reject, response);
|
||||||
|
|||||||
@@ -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) {
|
testTransparentGunzip: function (test) {
|
||||||
var data = {
|
var data = {
|
||||||
firstName: 'Fred',
|
firstName: 'Fred',
|
||||||
|
|||||||
Reference in New Issue
Block a user