From 22b1baae2891336173a5f9036d1c7ae90f241314 Mon Sep 17 00:00:00 2001 From: Dank074 Date: Sat, 7 Aug 2021 21:47:25 -0500 Subject: [PATCH] fixed max frame length --- pom.xml | 2 +- .../nitro/websockets/NetworkChannelInitializer.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 05fcd95..68ad2f6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.krews.plugin.nitro NitroWebsockets - 3.0 + 3.1 diff --git a/src/main/java/org/krews/plugin/nitro/websockets/NetworkChannelInitializer.java b/src/main/java/org/krews/plugin/nitro/websockets/NetworkChannelInitializer.java index ba87f9a..f9d1390 100644 --- a/src/main/java/org/krews/plugin/nitro/websockets/NetworkChannelInitializer.java +++ b/src/main/java/org/krews/plugin/nitro/websockets/NetworkChannelInitializer.java @@ -9,6 +9,7 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; +import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolConfig; import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; import io.netty.handler.logging.LoggingHandler; import io.netty.handler.ssl.SslContext; @@ -18,12 +19,20 @@ import org.krews.plugin.nitro.websockets.handlers.CustomHTTPHandler; import org.krews.plugin.nitro.websockets.ssl.SSLCertificateLoader; public class NetworkChannelInitializer extends ChannelInitializer { + private static final int MAX_FRAME_SIZE = 500000; + private final SslContext context; private final boolean isSSL; + private final WebSocketServerProtocolConfig config; public NetworkChannelInitializer() { context = SSLCertificateLoader.getContext(); isSSL = context != null; + config = WebSocketServerProtocolConfig.newBuilder() + .websocketPath("/") + .checkStartsWith(true) + .maxFramePayloadLength(MAX_FRAME_SIZE) + .build(); } @Override @@ -34,9 +43,9 @@ public class NetworkChannelInitializer extends ChannelInitializer ch.pipeline().addLast(context.newHandler(ch.alloc())); } ch.pipeline().addLast("httpCodec", new HttpServerCodec()); - ch.pipeline().addLast("objectAggregator", new HttpObjectAggregator(65536)); + ch.pipeline().addLast("objectAggregator", new HttpObjectAggregator(MAX_FRAME_SIZE)); ch.pipeline().addLast("customHttpHandler", new CustomHTTPHandler()); - ch.pipeline().addLast("protocolHandler", new WebSocketServerProtocolHandler("/", true)); + ch.pipeline().addLast("protocolHandler", new WebSocketServerProtocolHandler(config)); ch.pipeline().addLast("websocketCodec", new WebSocketCodec()); // Decoders.