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
aba9c552cd
commit
31b01c87e4
@ -65,6 +65,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);
|
||||
@ -75,9 +76,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
|
||||
@ -86,7 +93,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 ChannelHandlerAdapter {
|
||||
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 ChannelHandlerAdapter {
|
||||
}
|
||||
|
||||
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