Skip to content

Commit f44d9ce

Browse files
committed
Fixing redirect behaviour
1 parent 7ec97dd commit f44d9ce

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/adapters/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = function httpAdapter(resolve, reject, config) {
4545
// Parse url
4646
var parsed = url.parse(config.url);
4747
var options = {
48-
host: parsed.hostname,
48+
hostname: parsed.hostname,
4949
port: parsed.port,
5050
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
5151
method: config.method,

test/unit/adapters/http.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var axios = require('../../../index');
22
var http = require('http');
3+
var url = require('url');
34
var zlib = require('zlib');
45
var server;
56

@@ -28,6 +29,27 @@ module.exports = {
2829
});
2930
},
3031

32+
testRedirect: function (test) {
33+
var str = 'test response';
34+
35+
server = http.createServer(function (req, res) {
36+
var parsed = url.parse(req.url);
37+
38+
if (parsed.pathname === '/one') {
39+
res.setHeader('Location', '/two');
40+
res.statusCode = 302;
41+
res.end();
42+
} else {
43+
res.end(str);
44+
}
45+
}).listen(4444, function () {
46+
axios.get('http://localhost:4444/one').then(function (res) {
47+
test.equal(res.data, str);
48+
test.done();
49+
});
50+
});
51+
},
52+
3153
testTransparentGunzip: function (test) {
3254
var data = {
3355
firstName: 'Fred',

0 commit comments

Comments
 (0)