Adds port to the host header value. Due to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23 the port should be added if it differs from the default port. To simplify the code we just always add the port.

This commit is contained in:
Andrej Golovnin 2013-06-16 21:48:00 +02:00 committed by Trustin Lee
parent c86155e4d4
commit c07b0cac70

View File

@ -117,15 +117,15 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
} }
// Format request // Format request
int wsPort = wsURL.getPort();
FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path); FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path);
HttpHeaders headers = request.headers(); HttpHeaders headers = request.headers();
headers.add(Names.UPGRADE, Values.WEBSOCKET.toLowerCase()) headers.add(Names.UPGRADE, Values.WEBSOCKET.toLowerCase())
.add(Names.CONNECTION, Values.UPGRADE) .add(Names.CONNECTION, Values.UPGRADE)
.add(Names.SEC_WEBSOCKET_KEY, key) .add(Names.SEC_WEBSOCKET_KEY, key)
.add(Names.HOST, wsURL.getHost()); .add(Names.HOST, wsURL.getHost() + ':' + wsPort);
int wsPort = wsURL.getPort();
String originValue = "http://" + wsURL.getHost(); String originValue = "http://" + wsURL.getHost();
if (wsPort != 80 && wsPort != 443) { if (wsPort != 80 && wsPort != 443) {
// if the port is not standard (80/443) its needed to add the port to the header. // if the port is not standard (80/443) its needed to add the port to the header.