Merge pull request #6 from hellpf/master

IPv6 URL support
This commit is contained in:
Naoyuki Kanezawa
2014-09-21 19:46:01 +09:00

View File

@@ -164,12 +164,21 @@ public class Socket extends Emitter {
public Socket(Options opts) {
if (opts.host != null) {
String[] pieces = opts.host.split(":");
boolean ipv6uri = opts.host.indexOf(']') != -1;
String[] pieces = ipv6uri ? opts.host.split("]:") : opts.host.split(":");
boolean ipv6 = (pieces.length > 2 || opts.host.indexOf("::") == -1);
if (ipv6) {
opts.hostname = opts.host;
} else {
opts.hostname = pieces[0];
if (ipv6uri) {
opts.hostname = opts.hostname.substring(1);
}
if (pieces.length > 1) {
opts.port = Integer.parseInt(pieces[pieces.length - 1]);
}
}
}
this.secure = opts.secure;
this.sslContext = opts.sslContext != null ? opts.sslContext : defaultSSLContext;