Spring Cloud Gateway不路由基于Web套接字的请求

时间:2020-01-09 06:02:01

标签: spring-websocket spring-cloud-gateway

为了为基于websocket的微服务添加路由,我有 根据{{​​3}}

配置了我的应用程序
  - 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服务

1 个答案:

答案 0 :(得分:1)

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 Cloud Gateway会请求标头,如here