mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
Merge pull request #198 from gschambers/redirect-hostname
Fixes redirect behavior to correctly set host /port
This commit is contained in:
@@ -45,7 +45,7 @@ module.exports = function httpAdapter(resolve, reject, config) {
|
|||||||
// Parse url
|
// Parse url
|
||||||
var parsed = url.parse(config.url);
|
var parsed = url.parse(config.url);
|
||||||
var options = {
|
var options = {
|
||||||
host: parsed.hostname,
|
hostname: parsed.hostname,
|
||||||
port: parsed.port,
|
port: parsed.port,
|
||||||
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
|
||||||
method: config.method,
|
method: config.method,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var axios = require('../../../index');
|
var axios = require('../../../index');
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
|
var url = require('url');
|
||||||
var zlib = require('zlib');
|
var zlib = require('zlib');
|
||||||
var server;
|
var server;
|
||||||
|
|
||||||
@@ -28,6 +29,27 @@ module.exports = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testRedirect: function (test) {
|
||||||
|
var str = 'test response';
|
||||||
|
|
||||||
|
server = http.createServer(function (req, res) {
|
||||||
|
var parsed = url.parse(req.url);
|
||||||
|
|
||||||
|
if (parsed.pathname === '/one') {
|
||||||
|
res.setHeader('Location', '/two');
|
||||||
|
res.statusCode = 302;
|
||||||
|
res.end();
|
||||||
|
} else {
|
||||||
|
res.end(str);
|
||||||
|
}
|
||||||
|
}).listen(4444, function () {
|
||||||
|
axios.get('http://localhost:4444/one').then(function (res) {
|
||||||
|
test.equal(res.data, str);
|
||||||
|
test.done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
testTransparentGunzip: function (test) {
|
testTransparentGunzip: function (test) {
|
||||||
var data = {
|
var data = {
|
||||||
firstName: 'Fred',
|
firstName: 'Fred',
|
||||||
|
|||||||
Reference in New Issue
Block a user