Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2 - Webflux - Websocket - Activate Compression

I'm using:

  • Spring Boot 2.1.0 Release
  • Webflux (not MVC)
  • Websocket
  • Reactive Netty

And I would like to compress the returned payload with "GZIP" (or any other compression). I've tried with the configuration in application.yml:

server.compression.enabled: true

But the payload returned is still in plain text.

Does anybody know how to resolve this? Thanks.

like image 934
P.Rousseau Avatar asked Dec 10 '25 15:12

P.Rousseau


1 Answers

The server.compression.enabled configuration property is about HTTP response compression, so this won't achieve the desired goal.

With WebSocket, you can activate per-message compression with a protocol extension, it it is supported by the container you've chosen. This has to be negotiated between the client and the server during the handshake using the Sec-WebSocket-Extensions. So in your case, activating it is not enough you need to enable that on the client as well. See rfc7692.

Some containers (like Jetty in recent versions) are enabling those compression extensions by default. In the case of Reactor Netty, I'm not sure this is the case.

For the next steps, you can:

  • Check that your client is sending that header and supports this protocol extension
  • Switch to Jetty to check if this works out of the box
  • If it works with Jetty and not with Reactor Netty, you should create an issue on their issue tracker since a piece of Netty infrastructure might be missing (WebSocketServerCompressionHandler?)

Edit

I've created reactor/reactor-netty#507.

like image 176
Brian Clozel Avatar answered Dec 13 '25 06:12

Brian Clozel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!