Skip to content

Commit

Permalink
Use default ports when no explicit port provided in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhwick committed Apr 25, 2018
1 parent 13a35bd commit e3c0613
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions url.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,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;
};
52 changes: 51 additions & 1 deletion util.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -12,5 +59,8 @@ module.exports = {
},
isNullOrUndefined: function(arg) {
return arg == null;
}
},
getPortFromProtocol: function(protocol) {
return defaultProtocolPorts[protocol.slice(0, -1)];
},
};

0 comments on commit e3c0613

Please sign in to comment.