Skip to content

Allow setting headers, cookies, and session in WebSocket handshakes#14012

Draft
mkurz wants to merge 2 commits into
playframework:mainfrom
mkurz:websocket-accepted-handshake-options
Draft

Allow setting headers, cookies, and session in WebSocket handshakes#14012
mkurz wants to merge 2 commits into
playframework:mainfrom
mkurz:websocket-accepted-handshake-options

Conversation

@mkurz

@mkurz mkurz commented Jun 16, 2026

Copy link
Copy Markdown
Member

WIP WIP WIP WIP

@mkurz mkurz changed the title llow setting headers, cookies, and session in WebSocket handshakes Allow setting headers, cookies, and session in WebSocket handshakes Jun 16, 2026
mkurz added 2 commits June 17, 2026 14:22
Allow accepted WebSocket handlers to attach response metadata to
the opening handshake. The new Accepted value carries the selected
subprotocol, response headers, and cookies alongside the message
flow.

Wire the metadata through the Scala and Java APIs and both server
backends. Pekko HTTP appends headers to the upgrade response, while
Netty uses a Play-specific handshaker factory so custom headers reach
the actual WebSocket handshake.

Document the new APIs and add integration coverage for custom
handshake headers and cookies on both server backends.
Let accepted WebSocket handlers update the Play session during the
opening handshake. Session data is baked with the configured session
cookie baker, matching normal Result behavior.

Expose the session helpers in Scala and Java, pass Java session data
through the route adapter, and cover the emitted PLAY_SESSION cookie
in the WebSocket integration tests.
@mkurz mkurz force-pushed the websocket-accepted-handshake-options branch from 2da613b to 8baa2db Compare June 17, 2026 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant