diff --git a/index.js b/index.js index fedd2a2..c89de48 100644 --- a/index.js +++ b/index.js @@ -8,12 +8,12 @@ http.request = function (params, cb) { params = url.parse(params) } if (!params) params = {}; - if (!params.host && !params.port) { - params.port = parseInt(window.location.port, 10); - } if (!params.host && params.hostname) { params.host = params.hostname; } + if (!params.host && !params.port) { + params.port = parseInt(window.location.port, 10); + } if (!params.protocol) { if (params.scheme) { diff --git a/test/request_url.js b/test/request_url.js index 1f58f2d..7eda466 100644 --- a/test/request_url.js +++ b/test/request_url.js @@ -66,6 +66,19 @@ test('Test alt protocol', function(t) { }); +test('Test host resolution with default port', function(t) { + var url = { + hostname: "external-host", + protocol: "https:" + }; + + var request = http.get(url, noop); + + t.equal( request.uri, 'https://external-host:443/', 'Url should be correct'); + t.end(); + +}); + test('Test string as parameters', function(t) { var url = '/api/foo'; var request = http.get(url, noop);