Spring Boot 2 - Webflux - Websocket - Netty - 压缩

理查德·O

我在用着

  • spring-boot-starter-web 2.3.1
  • 弹簧 webflux 5.2.7
  • spring-boot-starter-reactor-netty 2.3.1

我正在尝试使用Sec-WebSocket-Extensions: permessage-deflatewebsockets 响应。Netty 自修复507以来支持 websocket 解压相关问题)

但它不起作用(即,服务器不使用permessage-deflate请求标头中的提议)

而当我使用jetty with 时spring-boot-starter-jetty,它开箱即用,无需额外配置。

有谁知道如何解决这个问题?谢谢!

摩西王子

查看spring-webflux框架后,在reactor-netty中默认禁用压缩。实际上,类默认构造ReactorNettyRequestUpgradeStrategy函数使用默认值(压缩 = false)创建了类参数值WebsocketServerSpec的实例

Reactor-netty检查谓词websocketClientSpec.compress()以建立压缩支持。

所以websocketClientSpec.compress需要激活该参数

@Bean
public WebSocketHandlerAdapter handlerAdapter(WebSocketService webSocketService) {
return new WebSocketHandlerAdapter(webSocketService);
}
@Bean
public WebSocketService webSocketService() {
return new HandshakeWebSocketService(
new ReactorNettyRequestUpgradeStrategy(WebsocketServerSpec.builder().compress(true)));
}

结果握手: 在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Spring Boot 2-Webflux-Websocket-激活压缩

Spring Boot Webflux / Netty-检测关闭的连接

Spring WebFlux和WebSocket

与标准的Spring Boot,TomCat,Jetty,Servlet 3.1和Netty相比,Spring WebFlux有何优势?

Netty的WebSocket消息是否已压缩?

Spring WebFlux认证的WebSocket连接

Spring Webflux Netty http和https

如何配置Spring Boot 2 WebFlux以使用SSL?

如何使用 WebFlux 在 Spring Boot 2 中设置登录页面?

如何使用Spring Boot 2和WebFlux测试@Controller

使用Reactor Netty配置Spring Boot以监听2个端口

如何在Spring Boot 2中配置Netty

人们如何在生产中的 Reactor Netty 上使用 WebFlux 托管 Spring Boot 应用程序?

抛出异常Spring Boot Webflux

Spring Boot端点+ webSocket

Spring Boot + Websocket(SockJS)

Spring Boot Stomp WebSocket

如何在webflux中将spring boot websocket文本消息转换为自定义java对象(bean或DTO)

Spring Boot 2反应式Web WebSocket与DataRest冲突

带有自签名证书错误的Spring WebFlux Netty SSL

运行tomcat而不是Netty的Spring WebFlux应用程序

无法在Spring Webflux 2.1.0中启动Netty服务器

对于Spring WebFlux的WebClient,如何捕获Netty的异常(例如ProxyConnectException)

Spring Boot WebFlux测试未找到MockMvc

Spring Boot Webflux-验证配置属性

Mockito:需要但未调用 Webflux Spring boot

Spring Boot Webflux反应式API

记录未使用 Spring boot webflux react 持久化到 R2DB 中

Spring Boot OAuth2客户端凭据使用Webflux动态配置