当服务器需要区分大小写的标头时,Spring Cloud 网关无法建立 websocket 连接

问题描述

我有一个具有 websocket 连接的第三方 web 应用程序。期望升级、连接头名称区分大小写。我使用 spring cloud gateway 作为这个 webapp 的反向代理。所有 http 调用都成功,但对于 websocket 请求,我收到以下错误

io.netty.handler.codec.http.websocketx.WebSocketClientHandshakeException: 无效的握手响应 getStatus: 404 Not Found at io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13.verify(WebSocketClientHandshaker13.java:272) ~[netty-codec-http-4.1.65.Final.jar:4.1.65

WebSocketClientHandshaker 正在设置升级和连接标头,它是小写的。如何覆盖这些标头值?

application.yml 配置如下

spring:
  main:
    web-application-type: reactive
  profiles:
    active: dev
  cloud:
    gateway:
      globalcors:
        corsConfigurations:
          '[/**]':
              allowedOrigins: "*"
              allowedMethods: "*"
              allowedHeaders: "*"
      httpclient:
        pool:
          max-idle-time: 10s
      ssl:
        useInsecureTrustManager: true
      filter:
        remove-non-proxy-headers:
          headers:
            - Keep-Alive
            - TE
            - Trailer
            - transfer-encoding
      routes:
        - id : no_op
          uri: no://op
          predicates:
            - Path=/falcon/tunneling/**
        - id: reroute_ws
          uri: ws://localhost:5555
          predicates:
            - Path=/websocket/**
        - id: reroute_2
          uri: http://localhost:5555
          predicates:
            - Path=/**

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)