diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java
index <HASH>..<HASH> 100644
--- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java
+++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshaker.java
@@ -183,7 +183,7 @@ public abstract class WebSocketServerHandshaker {
             p.replace(ctx.name(), "wsdecoder", newWebsocketDecoder());
 
             encoderName = p.context(HttpResponseEncoder.class).name();
-            p.addAfter(encoderName, "wsencoder", newWebSocketEncoder());
+            p.addBefore(encoderName, "wsencoder", newWebSocketEncoder());
         }
         channel.writeAndFlush(response).addListener(new ChannelFutureListener() {
             @Override
[#<I>] Correctly add the wsencoder before the httpencoder as the httpencoder also handle ByteBuf