Spring 云网关不路由基于网络套接字的请求

Spring cloud gateway not routing web-socket based requests

为了为基于 websocket 的微服务添加路由,我有 根据 Spring cloud gateway documentation

配置我的应用程序
  - id: sample_service_web_socket_handshake_url
    uri: lb:ws://sample-service
    predicates:
    - Path=/notification-service-ws/**

上面notification-service-ws是websocket-service

的握手url

直接访问此 websocket 端点(没有 spring-cloud-gateway)会话已连接,没有问题

但是在尝试使用 spring-cloud-gateway 进行连接时,网关会给出以下警告日志

2020-01-09 10:44:02.923  WARN 5155 --- [-server-epoll-5] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://192.168.10.44:4260/notification-service-ws]: Response status 400 with reason "Invalid 'Upgrade' header: {Sec-WebSocket-Version=[13], Sec-WebSocket-Key=[0EJxcMdBmRhZ5suS/INKnQ==], Sec-WebSocket-Extensions=[permessage-deflate; client_max_window_bits], Host=[192.168.10.44:4260]}"

我已确认没有 HTTP 请求发送到 websocket 服务

将以下属性添加到 spring-cloud-gateway application.yml 文件后问题已解决:

spring:
  application:
    name: burraq-api-gateway
  profiles:
    active: dev
  cloud:
    gateway:
      filter:
        remove-non-proxy-headers:
          headers:
          - Proxy-Authenticate
          - Proxy-Authorization
          - Keep-Alive
          - TE
          - Trailer
          - Transfer-Encoding

发生此问题是因为 spring 云网关默认请求 headers 如前所述 here