diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java index 90ca81143e..488d2f4ec2 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java @@ -138,7 +138,15 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker { request.addHeader(Names.UPGRADE, Values.WEBSOCKET); request.addHeader(Names.CONNECTION, Values.UPGRADE); request.addHeader(Names.HOST, wsURL.getHost()); - request.addHeader(Names.ORIGIN, "http://" + wsURL.getHost()); + + int wsPort = wsURL.getPort(); + 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.SEC_WEBSOCKET_KEY1, key1); request.addHeader(Names.SEC_WEBSOCKET_KEY2, key2); if (getExpectedSubprotocol() != null && !getExpectedSubprotocol().equals("")) { diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java index 5e2d840e06..aa1e7532a5 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java @@ -122,7 +122,15 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker { request.addHeader(Names.CONNECTION, Values.UPGRADE); request.addHeader(Names.SEC_WEBSOCKET_KEY, key); request.addHeader(Names.HOST, wsURL.getHost()); - request.addHeader(Names.ORIGIN, "http://" + wsURL.getHost()); + + int wsPort = wsURL.getPort(); + 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; + } + if (protocol != null && !protocol.equals("")) { request.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, protocol); } diff --git a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java index 06f1e921a8..330c09a853 100644 --- a/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java +++ b/src/main/java/org/jboss/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java @@ -122,7 +122,15 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker { request.addHeader(Names.CONNECTION, Values.UPGRADE); request.addHeader(Names.SEC_WEBSOCKET_KEY, key); request.addHeader(Names.HOST, wsURL.getHost()); - request.addHeader(Names.ORIGIN, "http://" + wsURL.getHost()); + + int wsPort = wsURL.getPort(); + 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; + } + if (protocol != null && !protocol.equals("")) { request.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, protocol); }