diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java index 74c8971af9..2e9de8b56e 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker.java @@ -37,7 +37,6 @@ import io.netty.util.NetUtil; import io.netty.util.ReferenceCountUtil; import io.netty.util.internal.ThrowableUtil; -import java.net.InetSocketAddress; import java.net.URI; import java.nio.channels.ClosedChannelException; @@ -475,7 +474,7 @@ public abstract class WebSocketClientHandshaker { // if the port is not standard (80/443) its needed to add the port to the header. // See http://tools.ietf.org/html/rfc6454#section-6.2 - return NetUtil.toSocketAddressString(InetSocketAddress.createUnresolved(host, port)); + return NetUtil.toSocketAddressString(host, port); } static CharSequence websocketOriginValue(String host, int wsPort) { diff --git a/common/src/main/java/io/netty/util/NetUtil.java b/common/src/main/java/io/netty/util/NetUtil.java index 59946ef9a5..bc4960c58d 100644 --- a/common/src/main/java/io/netty/util/NetUtil.java +++ b/common/src/main/java/io/netty/util/NetUtil.java @@ -966,7 +966,7 @@ public final class NetUtil { public static String toSocketAddressString(String host, int port) { String portStr = String.valueOf(port); return newSocketAddressStringBuilder( - host, portStr, isValidIpV4Address(host)).append(portStr).toString(); + host, portStr, !isValidIpV6Address(host)).append(':').append(portStr).toString(); } private static StringBuilder newSocketAddressStringBuilder(String host, String port, boolean ipv4) {