diff --git a/netty-socketio-core/src/main/java/com/socketio4j/socketio/BasicConfiguration.java b/netty-socketio-core/src/main/java/com/socketio4j/socketio/BasicConfiguration.java index 8de03a02..2266e7be 100644 --- a/netty-socketio-core/src/main/java/com/socketio4j/socketio/BasicConfiguration.java +++ b/netty-socketio-core/src/main/java/com/socketio4j/socketio/BasicConfiguration.java @@ -67,6 +67,8 @@ public abstract class BasicConfiguration { protected boolean httpCompression = true; protected boolean websocketCompression = true; + protected int decompressionBufferSize = 0; + protected boolean randomSession = false; @@ -135,6 +137,7 @@ protected BasicConfiguration(BasicConfiguration conf) { setHttpCompression(conf.isHttpCompression()); setWebsocketCompression(conf.isWebsocketCompression()); + setDecompressionBufferSize(conf.getDecompressionBufferSize()); setRandomSession(conf.randomSession); setNeedClientAuth(conf.isNeedClientAuth()); setMetrics(conf.getMetrics()); @@ -452,6 +455,25 @@ public void setWebsocketCompression(boolean websocketCompression) { this.websocketCompression = websocketCompression; } + public int getDecompressionBufferSize() { + return decompressionBufferSize; + } + + /** + * Set the maximum decompression buffer size for WebSocket compression. + * Used to limit memory consumption during WebSocket message decompression. + *

+ * Default is 0 which means unlimited + * + * `@param` decompressionBufferSize - buffer size in bytes, or 0 for [unlimited/default] + */ + public void setDecompressionBufferSize(int decompressionBufferSize) { + if (decompressionBufferSize < 0) { + throw new IllegalArgumentException("decompressionBufferSize must be non-negative"); + } + this.decompressionBufferSize = decompressionBufferSize; + } + public boolean isWebsocketCompression() { return websocketCompression; } diff --git a/netty-socketio-core/src/main/java/com/socketio4j/socketio/SocketIOChannelInitializer.java b/netty-socketio-core/src/main/java/com/socketio4j/socketio/SocketIOChannelInitializer.java index 97910082..727a3908 100644 --- a/netty-socketio-core/src/main/java/com/socketio4j/socketio/SocketIOChannelInitializer.java +++ b/netty-socketio-core/src/main/java/com/socketio4j/socketio/SocketIOChannelInitializer.java @@ -195,7 +195,7 @@ protected Object newContinueResponse(HttpMessage start, int maxContentLength, pipeline.addLast(AUTHORIZE_HANDLER, authorizeHandler); pipeline.addLast(XHR_POLLING_TRANSPORT, xhrPollingTransport); if (configuration.isWebsocketCompression()) { - pipeline.addLast(WEB_SOCKET_TRANSPORT_COMPRESSION, new WebSocketServerCompressionHandler()); + pipeline.addLast(WEB_SOCKET_TRANSPORT_COMPRESSION, new WebSocketServerCompressionHandler(configuration.getDecompressionBufferSize())); } pipeline.addLast(WEB_SOCKET_TRANSPORT, webSocketTransport);