From eab122b00f83e2b9202e7681b2364fccf98f5a0a Mon Sep 17 00:00:00 2001 From: MRHwick Date: Wed, 25 Apr 2018 14:19:21 -0400 Subject: [PATCH] [New] Use default ports when no explicit port provided in URL --- url.js | 2 ++ util.js | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/url.js b/url.js index 79cb0a6..1701693 100644 --- a/url.js +++ b/url.js @@ -762,6 +762,8 @@ Url.prototype.parseHost = function () { this.port = port.substr(1); } host = host.substr(0, host.length - port.length); + } else { + this.port = getPortFromProtocol(this.protocol); } if (host) { this.hostname = host; } }; diff --git a/util.js b/util.js index cde2170..539d30f 100644 --- a/util.js +++ b/util.js @@ -1,5 +1,52 @@ 'use strict'; +var defaultProtocolPorts = { + "acap": 674, + "afp": 548, + "dict": 2628, + "dns": 53, + "file": null, + "ftp": 21, + "git": 9418, + "gopher": 70, + "http": 80, + "https": 443, + "imap": 143, + "ipp": 631, + "ipps": 631, + "irc": 194, + "ircs": 6697, + "ldap": 389, + "ldaps": 636, + "mms": 1755, + "msrp": 2855, + "msrps": null, + "mtqp": 1038, + "nfs": 111, + "nntp": 119, + "nntps": 563, + "pop": 110, + "prospero": 1525, + "redis": 6379, + "rsync": 873, + "rtsp": 554, + "rtsps": 322, + "rtspu": 5005, + "sftp": 22, + "smb": 445, + "snmp": 161, + "ssh": 22, + "steam": null, + "svn": 3690, + "telnet": 23, + "ventrilo": 3784, + "vnc": 5900, + "wais": 210, + "ws": 80, + "wss": 443, + "xmpp": null, +} + module.exports = { isString: function (arg) { return typeof arg === 'string'; @@ -12,5 +59,8 @@ module.exports = { }, isNullOrUndefined: function (arg) { return arg == null; - } + }, + getPortFromProtocol: function(protocol) { + return defaultProtocolPorts[protocol.slice(0, -1)]; + }, };