reactor / reactor-netty

TCP/HTTP/UDP/QUIC client/server with Reactor over Netty

Home Page:https://projectreactor.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to configure Websocket compression when both HttpProtocol.H2C and HttpProtocol.HTTP1.1 are configured

joebyneil opened this issue · comments

Expected Behavior

Websocket compression should be negotiated when both HTTP11 and H2C protocols are enabled, in the same way as when only HTTP11 protocol is enabled, and both the server and client support it.

Both the request and response contain a sec-websocket-extensions header indicating that compression is in use. (ie. permessage-deflate)

Actual Behavior

Websocket compression is not negotiated when HTTP11 and H2C are both enabled. The HttpClient correctly sends the extension, but the HttpServer does not apply it. The response does not contain the extensions header, and debug logs show that the compression handler was removed.

Using only HTTP11 or using H2 instead of H2C works as expected.

Steps to Reproduce

@Test
public void testCompression() {
    var websocketServerSpec = WebsocketServerSpec.builder().compress(true).build();
    var compressionExpected = HttpServer.create()
        .protocol(HttpProtocol.HTTP11, HttpProtocol.H2C)
        .handle((req, res) ->
            res.sendWebsocket((in, out) -> out.sendString(Mono.just("test")), websocketServerSpec))
        .bindNow();

    var responseHeaders = new HashMap<String, String>();
    var webSocketClientSpec = WebsocketClientSpec.builder().compress(true).build();
    var connectionClient = HttpClient.create()
        .remoteAddress(compressionExpected::address)
        .websocket(webSocketClientSpec)
        .handle((in, out) -> {
            var headers = in.headers();
            headers.forEach(header -> responseHeaders.put(header.getKey(), header.getValue()));
            return out.sendClose();
        }).then().block();

    assertThat(responseHeaders.keySet()).contains("sec-websocket-extensions");
    assertThat(responseHeaders.get("sec-websocket-extensions")).contains("permessage-deflate");
}

Your Environment

  • Reactor version(s) used:
    reactor-netty 1.1.12
  • JVM version (java -version):
    openjdk 17.0.6 2023-01-17 LTS
    OpenJDK Runtime Environment Zulu17.40+19-CA (build 17.0.6+10-LTS)
    OpenJDK 64-Bit Server VM Zulu17.40+19-CA (build 17.0.6+10-LTS, mixed mode, sharing)
  • OS and version (eg. uname -a):
    XXX.local 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 arm64

@joebyneil Thanks for the reproducible example! PR #3037 should fix the issue.

Thank you