Skip to content

Commit e3c0613

Browse files
committed
Use default ports when no explicit port provided in URL
1 parent 13a35bd commit e3c0613

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

url.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,8 @@ Url.prototype.parseHost = function() {
727727
this.port = port.substr(1);
728728
}
729729
host = host.substr(0, host.length - port.length);
730+
} else {
731+
this.port = getPortFromProtocol(this.protocol);
730732
}
731733
if (host) this.hostname = host;
732734
};

util.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,52 @@
11
'use strict';
22

3+
var defaultProtocolPorts = {
4+
"acap": 674,
5+
"afp": 548,
6+
"dict": 2628,
7+
"dns": 53,
8+
"file": null,
9+
"ftp": 21,
10+
"git": 9418,
11+
"gopher": 70,
12+
"http": 80,
13+
"https": 443,
14+
"imap": 143,
15+
"ipp": 631,
16+
"ipps": 631,
17+
"irc": 194,
18+
"ircs": 6697,
19+
"ldap": 389,
20+
"ldaps": 636,
21+
"mms": 1755,
22+
"msrp": 2855,
23+
"msrps": null,
24+
"mtqp": 1038,
25+
"nfs": 111,
26+
"nntp": 119,
27+
"nntps": 563,
28+
"pop": 110,
29+
"prospero": 1525,
30+
"redis": 6379,
31+
"rsync": 873,
32+
"rtsp": 554,
33+
"rtsps": 322,
34+
"rtspu": 5005,
35+
"sftp": 22,
36+
"smb": 445,
37+
"snmp": 161,
38+
"ssh": 22,
39+
"steam": null,
40+
"svn": 3690,
41+
"telnet": 23,
42+
"ventrilo": 3784,
43+
"vnc": 5900,
44+
"wais": 210,
45+
"ws": 80,
46+
"wss": 443,
47+
"xmpp": null,
48+
}
49+
350
module.exports = {
451
isString: function(arg) {
552
return typeof(arg) === 'string';
@@ -12,5 +59,8 @@ module.exports = {
1259
},
1360
isNullOrUndefined: function(arg) {
1461
return arg == null;
15-
}
62+
},
63+
getPortFromProtocol: function(protocol) {
64+
return defaultProtocolPorts[protocol.slice(0, -1)];
65+
},
1666
};

0 commit comments

Comments
 (0)