From e59722037c650228617fb94d7c0e4bd733b6d97b Mon Sep 17 00:00:00 2001 From: ktqco <75426052+ktqco@users.noreply.github.com> Date: Fri, 18 Jun 2021 10:45:32 +0100 Subject: [PATCH] Accept smaller `server_max_window_bits` than requested (#11394) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Motivation: Netty will fail a handshake for the Per-Message Deflate WebSocket extension if the server response contains a smaller `server_max_window_bits` value than the client offered. However, this is allowed by RFC 7692: > A server accepts an extension negotiation offer with this parameter > by including the “server_max_window_bits” extension parameter in the > extension negotiation response to send back to the client with the > same or smaller value as the offer. Modifications: - Allow the server to respond with a smaller value than offered. - Change the unit tests to test for this. Result: The client will not fail when the server indicates it is using a smaller window size than offered by the client. --- .../compression/PerMessageDeflateClientExtensionHandshaker.java | 2 +- .../PerMessageDeflateClientExtensionHandshakerTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshaker.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshaker.java index 84c0a8d746..db364f5190 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshaker.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshaker.java @@ -183,7 +183,7 @@ public final class PerMessageDeflateClientExtensionHandshaker implements WebSock } if ((requestedServerNoContext && !serverNoContext) || - requestedServerWindowSize != serverWindowSize) { + requestedServerWindowSize < serverWindowSize) { succeed = false; } diff --git a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshakerTest.java b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshakerTest.java index d44244ed6e..3cc7492219 100644 --- a/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshakerTest.java +++ b/codec-http/src/test/java/io/netty/handler/codec/http/websocketx/extensions/compression/PerMessageDeflateClientExtensionHandshakerTest.java @@ -90,7 +90,7 @@ public class PerMessageDeflateClientExtensionHandshakerTest { parameters = new HashMap<>(); parameters.put(CLIENT_MAX_WINDOW, "12"); - parameters.put(SERVER_MAX_WINDOW, "10"); + parameters.put(SERVER_MAX_WINDOW, "8"); parameters.put(CLIENT_NO_CONTEXT, null); parameters.put(SERVER_NO_CONTEXT, null);