From 743596aaeac455f009d4b0c6805ea8322c785b0d Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 30 May 2012 19:18:08 -0700 Subject: [PATCH] Fix a bug where first websocket frame is discarded (#332) --- .../codec/http/websocketx/WebSocketClientHandshaker00.java | 7 +++---- .../codec/http/websocketx/WebSocketClientHandshaker08.java | 3 ++- .../codec/http/websocketx/WebSocketClientHandshaker13.java | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java index d89567a39e..8b402ec99f 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker00.java @@ -152,7 +152,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker { request.addHeader(Names.ORIGIN, originValue); request.addHeader(Names.SEC_WEBSOCKET_KEY1, key1); request.addHeader(Names.SEC_WEBSOCKET_KEY2, key2); - String expectedSubprotocol = this.getExpectedSubprotocol(); + String expectedSubprotocol = getExpectedSubprotocol(); if (expectedSubprotocol != null && !expectedSubprotocol.equals("")) { request.addHeader(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol); } @@ -223,9 +223,8 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker { String subprotocol = response.getHeader(Names.SEC_WEBSOCKET_PROTOCOL); setActualSubprotocol(subprotocol); - channel.pipeline().replace( - HttpResponseDecoder.class, "ws-decoder", - new WebSocket00FrameDecoder(getMaxFramePayloadLength())); + channel.pipeline().get(HttpResponseDecoder.class).replace( + "ws-decoder", new WebSocket00FrameDecoder(getMaxFramePayloadLength())); setHandshakeComplete(); } diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java index f25d4ffab4..3d59e1ffec 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker08.java @@ -200,7 +200,8 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker { String subprotocol = response.getHeader(Names.SEC_WEBSOCKET_PROTOCOL); setActualSubprotocol(subprotocol); - channel.pipeline().replace(HttpResponseDecoder.class, "ws-decoder", + channel.pipeline().get(HttpResponseDecoder.class).replace( + "ws-decoder", new WebSocket08FrameDecoder(false, allowExtensions, getMaxFramePayloadLength())); setHandshakeComplete(); diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java index 62dc79d5ec..a9739f6d56 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshaker13.java @@ -200,7 +200,8 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker { String subprotocol = response.getHeader(Names.SEC_WEBSOCKET_PROTOCOL); setActualSubprotocol(subprotocol); - channel.pipeline().replace(HttpResponseDecoder.class, "ws-decoder", + channel.pipeline().get(HttpResponseDecoder.class).replace( + "ws-decoder", new WebSocket13FrameDecoder(false, allowExtensions, getMaxFramePayloadLength())); setHandshakeComplete();