Skip to content

Commit

Permalink
Merge pull request #198 from gschambers/redirect-hostname
Browse files Browse the repository at this point in the history
Fixes redirect behavior to correctly set host
/port
  • Loading branch information
mzabriskie committed Jan 19, 2016
2 parents 7ec97dd + f44d9ce commit a473744
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = function httpAdapter(resolve, reject, config) {
// Parse url
var parsed = url.parse(config.url);
var options = {
host: parsed.hostname,
hostname: parsed.hostname,
port: parsed.port,
path: buildURL(parsed.path, config.params, config.paramsSerializer).replace(/^\?/, ''),
method: config.method,
Expand Down
22 changes: 22 additions & 0 deletions test/unit/adapters/http.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var axios = require('../../../index');
var http = require('http');
var url = require('url');
var zlib = require('zlib');
var server;

Expand Down Expand Up @@ -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) {
var data = {
firstName: 'Fred',
Expand Down

0 comments on commit a473744

Please sign in to comment.