Spring Boot 2 - Webflux - Websocket - Activate Compression

被刻印的时光 ゝ 提交于 2021-02-09 07:01:27

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/53179626/spring-boot-2-webflux-websocket-activate-compression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!