fixed max frame length

This commit is contained in:
Dank074 2021-08-07 21:47:25 -05:00
parent c5566e11be
commit 22b1baae28
2 changed files with 12 additions and 3 deletions

View File

@ -6,7 +6,7 @@
<groupId>org.krews.plugin.nitro</groupId> <groupId>org.krews.plugin.nitro</groupId>
<artifactId>NitroWebsockets</artifactId> <artifactId>NitroWebsockets</artifactId>
<version>3.0</version> <version>3.1</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>

View File

@ -9,6 +9,7 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec; 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.codec.http.websocketx.WebSocketServerProtocolHandler;
import io.netty.handler.logging.LoggingHandler; import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.ssl.SslContext; 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; import org.krews.plugin.nitro.websockets.ssl.SSLCertificateLoader;
public class NetworkChannelInitializer extends ChannelInitializer<SocketChannel> { public class NetworkChannelInitializer extends ChannelInitializer<SocketChannel> {
private static final int MAX_FRAME_SIZE = 500000;
private final SslContext context; private final SslContext context;
private final boolean isSSL; private final boolean isSSL;
private final WebSocketServerProtocolConfig config;
public NetworkChannelInitializer() { public NetworkChannelInitializer() {
context = SSLCertificateLoader.getContext(); context = SSLCertificateLoader.getContext();
isSSL = context != null; isSSL = context != null;
config = WebSocketServerProtocolConfig.newBuilder()
.websocketPath("/")
.checkStartsWith(true)
.maxFramePayloadLength(MAX_FRAME_SIZE)
.build();
} }
@Override @Override
@ -34,9 +43,9 @@ public class NetworkChannelInitializer extends ChannelInitializer<SocketChannel>
ch.pipeline().addLast(context.newHandler(ch.alloc())); ch.pipeline().addLast(context.newHandler(ch.alloc()));
} }
ch.pipeline().addLast("httpCodec", new HttpServerCodec()); 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("customHttpHandler", new CustomHTTPHandler());
ch.pipeline().addLast("protocolHandler", new WebSocketServerProtocolHandler("/", true)); ch.pipeline().addLast("protocolHandler", new WebSocketServerProtocolHandler(config));
ch.pipeline().addLast("websocketCodec", new WebSocketCodec()); ch.pipeline().addLast("websocketCodec", new WebSocketCodec());
// Decoders. // Decoders.