[英]Can I use HandshakeInterceptor With graphql-spring-boot-starter To Get Cookies?
I have a Spring Boot java app which serves up GraphQL subscriptions via graphql-spring-boot-starter.我有一个 Spring 启动 java 应用程序,它通过 graphql-spring-boot-starter 提供 GraphQL 订阅。
I would like to access cookies in some fashion.我想以某种方式访问 cookies。
In other (not graphql) contexts, I've seen people use HandshakeInterceptor to get cookies before the websocket handshake.在其他(不是 graphql)上下文中,我看到人们在 websocket 握手之前使用 HandshakeInterceptor 来获取 cookies。
I don't manually set up the websocket code, it is autowired via graphql-spring-boot-starter.我没有手动设置 websocket 代码,它是通过 graphql-spring-boot-starter 自动装配的。 I see non-graphql examples of people overriding registerStompEndpoints on their websocket configuration, but in my case I don't have any explicit websocket configuration, it is auto created.
我看到人们在他们的 websocket 配置上覆盖 registerStompEndpoints 的非 graphql 示例,但在我的情况下,我没有任何明确的 websocket 配置,它是自动创建的。
Is there a way I can wire a HandshakeInterceptor into graphql-spring-boot-starter's functionality?有没有办法可以将 HandshakeInterceptor 连接到 graphql-spring-boot-starter 的功能中? I already tried creating a HandshakeInterceptor bean, but that appears to do nothing.
我已经尝试过创建一个 HandshakeInterceptor bean,但这似乎无济于事。
My setup was assuming some things about graphql-java that are no longer true.我的设置是假设有关 graphql-java 的一些事情不再正确。 And I was not familiar with the websocket context.
而且我不熟悉 websocket 上下文。
The solution is to use GraphQLWebSocketContext, which provides HandshakeRequest, allows you to do:解决方案是使用 GraphQLWebSocketContext,它提供了 HandshakeRequest,可以让你做:
graphQLWebSocketContext.getHandshakeRequest().getHeaders().get( "cookie" )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.