Skip to content

Subscriber context not propagated to WebSocketHandler for Tomcat websockets #26210

@philsttr

Description

@philsttr

In a WebFlux application that uses Tomcat as the webserver, the reactor subscriber context is not currently propagated from WebFilters down to WebSocketHandlers. Therefore objects put into the subscriber context (such as the spring security context) by WebFilters are not available to WebSocketHandlers.

For comparison, when reactor-netty is used as the webserver, the reactor subscriber context is propagated from WebFilters to WebSocketHandlers properly.

I have a WebSocketHandler that needs to access the spring security context. Unfortunately, this is not currently possible when using tomcat as the webserver.

The disconnect occurs between TomcatRequestUpgradeStrategy and StandardWebSocketHandlerAdapter...

  1. TomcatRequestUpgradeStrategy.upgrade constructs a StandardWebSocketHandlerAdapter and delegates to the container's websocket upgrade logic (see here). The context is lost at this point.
  2. The container performs the websocket upgrade and calls into StandardWebSocketHandlerAdapter.onOpen.
  3. StandardWebSocketHandlerAdapter.onOpen then delegates to WebSocketHandler.handle (see here). I need access to items in the subscriber context within aWebSocketHandler, but the context is empty.

To propagate the context, I believe TomcatRequestUpgradeStrategy.upgrade could pass the active context to the StandardWebSocketHandlerAdapter upon construction (during step 1 above).
Then StandardWebSocketHandlerAdapter.onOpen could pass the context to the handler stream (during step 3 above).

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions