expectedChallengeResponseString));
}
// Format request
int wsPort = wsURL.getPort();
HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
request.addHeader(Names.UPGRADE, Values.WEBSOCKET.toLowerCase());
request.addHeader(Names.CONNECTION, Values.UPGRADE);
request.addHeader(Names.SEC_WEBSOCKET_KEY, key);
request.addHeader(Names.HOST, wsURL.getHost() + ':' + wsPort);
String originValue = "http://" + wsURL.getHost();
if (wsPort != 80 && wsPort != 443) {
// 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
originValue = originValue + ':' + wsPort;
}
request.addHeader(Names.ORIGIN, originValue);
String expectedSubprotocol = getExpectedSubprotocol();
if (expectedSubprotocol != null && expectedSubprotocol.length() != 0) {
request.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
}
request.addHeader(Names.SEC_WEBSOCKET_VERSION, "13");
if (customHeaders != null) {
for (Map.Entry<String, String> e: customHeaders.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
}
ChannelFuture future = channel.write(request);
final ChannelFuture handshakeFuture = new DefaultChannelFuture(channel, false);