Spring Boot 2 - Webflux - Websocket - 激活压缩 [英] Spring Boot 2 - Webflux - Websocket - Activate Compression

查看:105
本文介绍了Spring Boot 2 - Webflux - Websocket - 激活压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用:

  • Spring Boot 2.1.0 发布
  • Webflux(非 MVC)
  • Websocket
  • 反应式网络

我想用GZIP"(或任何其他压缩方式)压缩返回的有效负载.我已经尝试过 application.yml 中的配置:

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

但是返回的payload仍然是纯文本的.

But the payload returned is still in plain text.

有人知道如何解决这个问题吗?谢谢.

Does anybody know how to resolve this? Thanks.

推荐答案

server.compression.enabled 配置属性是关于 HTTP 响应压缩的,所以这不会达到预期的目标.

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

使用 WebSocket,您可以使用协议扩展激活每条消息压缩,它由您选择的容器支持.这必须在握手期间使用 Sec-WebSocket-Extensions 在客户端和服务器之间进行协商.因此,在您的情况下,仅激活它是不够的,您还需要在客户端上启用它.请参阅 rfc7692.

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.

某些容器(如最近版本中的 Jetty)默认启用这些压缩扩展.就 Reactor Netty 而言,我不确定是否是这种情况.

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:

  • 检查您的客户端是否正在发送该标头并支持此协议扩展
  • 切换到 Jetty 以检查这是否开箱即用
  • 如果它适用于 Jetty 而不适用于 Reactor Netty,您应该针对他们的问题创建问题跟踪器,因为可能缺少一块 Netty 基础设施 (WebSocketServerCompressionHandler?)
  • 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?)

我创建了 reactor/reactor-netty#507.

这篇关于Spring Boot 2 - Webflux - Websocket - 激活压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆