Made websocket maxFramePayloadSize configurable from WebSocketServerProtocolHandler.
Motivation: Currently there's no way to configure maxFramePayloadSize from WebSocketServerProtocolHandler, which is the most used entry point of WebSocket server. Modifications: Added another constructor for maxFramePayloadSize. Result: We can configure max frame size for websocket packet in WebSocketServerProtocolHandler. It will also keep backward compatibility with default max size: 65536. (65536 is hard-coded max size in previous version of Netty)
This commit is contained in:
parent
9752f37fa0
commit
d713f015da
@ -66,6 +66,7 @@ public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler {
|
||||
private final String websocketPath;
|
||||
private final String subprotocols;
|
||||
private final boolean allowExtensions;
|
||||
private final int maxFramePayloadLength;
|
||||
|
||||
public WebSocketServerProtocolHandler(String websocketPath) {
|
||||
this(websocketPath, null, false);
|
||||
@ -76,9 +77,15 @@ public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler {
|
||||
}
|
||||
|
||||
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions) {
|
||||
this(websocketPath, subprotocols, allowExtensions, 65536);
|
||||
}
|
||||
|
||||
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols,
|
||||
boolean allowExtensions, int maxFrameSize) {
|
||||
this.websocketPath = websocketPath;
|
||||
this.subprotocols = subprotocols;
|
||||
this.allowExtensions = allowExtensions;
|
||||
this.maxFramePayloadLength = maxFrameSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -87,7 +94,8 @@ public class WebSocketServerProtocolHandler extends WebSocketProtocolHandler {
|
||||
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));
|
||||
new WebSocketServerProtocolHandshakeHandler(websocketPath, subprotocols,
|
||||
allowExtensions, maxFramePayloadLength));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,12 +40,14 @@ class WebSocketServerProtocolHandshakeHandler extends ChannelInboundHandlerAdapt
|
||||
private final String websocketPath;
|
||||
private final String subprotocols;
|
||||
private final boolean allowExtensions;
|
||||
private final int maxFramePayloadSize;
|
||||
|
||||
WebSocketServerProtocolHandshakeHandler(String websocketPath, String subprotocols,
|
||||
boolean allowExtensions) {
|
||||
boolean allowExtensions, int maxFrameSize) {
|
||||
this.websocketPath = websocketPath;
|
||||
this.subprotocols = subprotocols;
|
||||
this.allowExtensions = allowExtensions;
|
||||
this.maxFramePayloadSize = maxFrameSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -58,7 +60,8 @@ class WebSocketServerProtocolHandshakeHandler extends ChannelInboundHandlerAdapt
|
||||
}
|
||||
|
||||
final WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
|
||||
getWebSocketLocation(ctx.pipeline(), req, websocketPath), subprotocols, allowExtensions);
|
||||
getWebSocketLocation(ctx.pipeline(), req, websocketPath), subprotocols,
|
||||
allowExtensions, maxFramePayloadSize);
|
||||
final WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req);
|
||||
if (handshaker == null) {
|
||||
WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
|
||||
|
Loading…
Reference in New Issue
Block a user