[#4794] Support window size flag by default if ZlibCodecFactory supports it.
Motivation: If the ZlibCodecFactory can support using a custom window size we should support it by default in the websocket extensions as well. Modifications: Detect if a custom window size can be handled by the ZlibCodecFactory and if so enable it by default for PerMessageDeflate*ExtensionHandshaker. Result: Support window size flag by default in most installations.
This commit is contained in:
parent
7a562943ad
commit
a0758e7e60
@ -17,6 +17,8 @@ package io.netty.handler.codec.http.websocketx.extensions.compression;
|
|||||||
|
|
||||||
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
||||||
PerMessageDeflateServerExtensionHandshaker.*;
|
PerMessageDeflateServerExtensionHandshaker.*;
|
||||||
|
|
||||||
|
import io.netty.handler.codec.compression.ZlibCodecFactory;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtension;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtension;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandshaker;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtensionHandshaker;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
||||||
@ -43,7 +45,7 @@ public final class PerMessageDeflateClientExtensionHandshaker implements WebSock
|
|||||||
* Constructor with default configuration.
|
* Constructor with default configuration.
|
||||||
*/
|
*/
|
||||||
public PerMessageDeflateClientExtensionHandshaker() {
|
public PerMessageDeflateClientExtensionHandshaker() {
|
||||||
this(6, false, MAX_WINDOW_SIZE, false, false);
|
this(6, ZlibCodecFactory.isSupportingWindowSizeAndMemLevel(), MAX_WINDOW_SIZE, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.handler.codec.http.websocketx.extensions.compression;
|
package io.netty.handler.codec.http.websocketx.extensions.compression;
|
||||||
|
|
||||||
|
import io.netty.handler.codec.compression.ZlibCodecFactory;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionDecoder;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionDecoder;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionEncoder;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionEncoder;
|
||||||
@ -50,7 +51,7 @@ public final class PerMessageDeflateServerExtensionHandshaker implements WebSock
|
|||||||
* Constructor with default configuration.
|
* Constructor with default configuration.
|
||||||
*/
|
*/
|
||||||
public PerMessageDeflateServerExtensionHandshaker() {
|
public PerMessageDeflateServerExtensionHandshaker() {
|
||||||
this(6, false, MAX_WINDOW_SIZE, false, false);
|
this(6, ZlibCodecFactory.isSupportingWindowSizeAndMemLevel(), MAX_WINDOW_SIZE, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,6 +18,8 @@ package io.netty.handler.codec.http.websocketx.extensions.compression;
|
|||||||
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
import static io.netty.handler.codec.http.websocketx.extensions.compression.
|
||||||
PerMessageDeflateServerExtensionHandshaker.*;
|
PerMessageDeflateServerExtensionHandshaker.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import io.netty.handler.codec.compression.ZlibCodecFactory;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtension;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketClientExtension;
|
||||||
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
import io.netty.handler.codec.http.websocketx.extensions.WebSocketExtensionData;
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ public class PerMessageDeflateClientExtensionHandshakerTest {
|
|||||||
WebSocketExtensionData data = handshaker.newRequestData();
|
WebSocketExtensionData data = handshaker.newRequestData();
|
||||||
|
|
||||||
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, data.name());
|
assertEquals(PERMESSAGE_DEFLATE_EXTENSION, data.name());
|
||||||
assertTrue(data.parameters().isEmpty());
|
assertEquals(ZlibCodecFactory.isSupportingWindowSizeAndMemLevel() ? 1 : 0, data.parameters().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -31,6 +31,7 @@ public final class ZlibCodecFactory {
|
|||||||
|
|
||||||
private static final boolean noJdkZlibDecoder;
|
private static final boolean noJdkZlibDecoder;
|
||||||
private static final boolean noJdkZlibEncoder;
|
private static final boolean noJdkZlibEncoder;
|
||||||
|
private static final boolean supportsWindowSizeAndMemLevel;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
noJdkZlibDecoder = SystemPropertyUtil.getBoolean("io.netty.noJdkZlibDecoder",
|
noJdkZlibDecoder = SystemPropertyUtil.getBoolean("io.netty.noJdkZlibDecoder",
|
||||||
@ -39,6 +40,15 @@ public final class ZlibCodecFactory {
|
|||||||
|
|
||||||
noJdkZlibEncoder = SystemPropertyUtil.getBoolean("io.netty.noJdkZlibEncoder", false);
|
noJdkZlibEncoder = SystemPropertyUtil.getBoolean("io.netty.noJdkZlibEncoder", false);
|
||||||
logger.debug("-Dio.netty.noJdkZlibEncoder: {}", noJdkZlibEncoder);
|
logger.debug("-Dio.netty.noJdkZlibEncoder: {}", noJdkZlibEncoder);
|
||||||
|
|
||||||
|
supportsWindowSizeAndMemLevel = noJdkZlibDecoder || PlatformDependent.javaVersion() >= 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if specify a custom window size and mem level is supported.
|
||||||
|
*/
|
||||||
|
public static boolean isSupportingWindowSizeAndMemLevel() {
|
||||||
|
return supportsWindowSizeAndMemLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ZlibEncoder newZlibEncoder(int compressionLevel) {
|
public static ZlibEncoder newZlibEncoder(int compressionLevel) {
|
||||||
|
Loading…
Reference in New Issue
Block a user