From d492aa84c8ac0d74c97e202cbdcf3049b0afb517 Mon Sep 17 00:00:00 2001 From: andre Date: Sun, 7 Jun 2015 18:10:16 +0200 Subject: [PATCH 1/2] Reorder host resolution to cascade into port detection --- index.js | 6 +++--- test/request_url.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) 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..85820a6 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); From 76fbdf18cbc3ecf4eb9abe1cfe226dd80383c63c Mon Sep 17 00:00:00 2001 From: andre Date: Sun, 7 Jun 2015 18:18:26 +0200 Subject: [PATCH 2/2] typo: fixed indentation in request_url.js --- test/request_url.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/request_url.js b/test/request_url.js index 85820a6..7eda466 100644 --- a/test/request_url.js +++ b/test/request_url.js @@ -69,7 +69,7 @@ test('Test alt protocol', function(t) { test('Test host resolution with default port', function(t) { var url = { hostname: "external-host", - protocol: "https:" + protocol: "https:" }; var request = http.get(url, noop);