From 67d077af2e7e2db0ee61dff4f1f66a0bfb3b517e Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Sun, 6 Apr 2014 21:26:38 +1200 Subject: [PATCH] Fix ports when connecting to 80/443 from non-80/443 host --- lib/url.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/url.js b/lib/url.js index d96a9fa2..064ab3f6 100644 --- a/lib/url.js +++ b/lib/url.js @@ -51,9 +51,13 @@ function url(uri, loc){ } // make sure we treat `localhost:80` and `localhost` equally - if ((/(http|ws)/.test(obj.protocol) && 80 == obj.port) || - (/(http|ws)s/.test(obj.protocol) && 443 == obj.port)) { - delete obj.port; + if (null == obj.port) { + if (/^(http|ws):$/.test(obj.protocol)) { + obj.port = 80; + } + else if (/^(http|ws)s:$/.test(obj.protocol)) { + obj.port = 443; + } } obj.path = obj.path || '/';