From 6c2053bae57cd09684433ec640708a17b41ce42f Mon Sep 17 00:00:00 2001 From: norman Date: Mon, 10 Sep 2012 07:18:26 +0200 Subject: [PATCH] Check if WebSocketServerProtocolHandshakeHandler is already in the pipeline before adding it. See #587 --- .../websocketx/WebSocketServerProtocolHandler.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java index 1edc552003..e94f2567ae 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerProtocolHandler.java @@ -20,6 +20,7 @@ import io.netty.buffer.Unpooled; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundMessageHandlerAdapter; +import io.netty.channel.ChannelPipeline; import io.netty.handler.codec.http.DefaultHttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.util.AttributeKey; @@ -53,9 +54,12 @@ public class WebSocketServerProtocolHandler extends ChannelInboundMessageHandler @Override public void afterAdd(ChannelHandlerContext ctx) { - // Add the WebSocketHandshakeHandler before this one. - ctx.pipeline().addBefore(ctx.name(), WebSocketServerProtocolHandshakeHandler.class.getName(), - new WebSocketServerProtocolHandshakeHandler(websocketPath, subprotocols, allowExtensions)); + ChannelPipeline cp = ctx.pipeline(); + if (cp.get(WebSocketServerProtocolHandshakeHandler.class) == null) { + // Add the WebSocketHandshakeHandler before this one. + ctx.pipeline().addBefore(ctx.name(), WebSocketServerProtocolHandshakeHandler.class.getName(), + new WebSocketServerProtocolHandshakeHandler(websocketPath, subprotocols, allowExtensions)); + } } @Override