Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access to Request or headers in onUpgrade closure on client-side #151

Open
edonv opened this issue Jun 20, 2024 · 1 comment
Open

Add access to Request or headers in onUpgrade closure on client-side #151

edonv opened this issue Jun 20, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@edonv
Copy link

edonv commented Jun 20, 2024

Is your feature request related to a problem? Please describe.
I'm using WebSocketKit on both the Vapor server-side, and from a client-side. For my own custom authentication system, I'd like to send something in the initial request headers from the client (already possible), then do some stuff with it to generate an authentication token on the server-side (already possible, server-side shouldUpgrade closure), and then send the token back in the response headers (already possible, server-side shouldUpgrade closure). The problem is the client being able to receive that. As of now, WebSocketKit doesn't give the client-side connecting functions access to the Request or headers in the upgrading Request from the server.

I found where it's accessed in the package code, but it's not made accessible to the client:

let websocketUpgrader = NIOWebSocketClientUpgrader(
maxFrameSize: self.configuration.maxFrameSize,
automaticErrorHandling: true,
upgradePipelineHandler: { channel, req in
return WebSocket.client(on: channel, config: .init(clientConfig: self.configuration), onUpgrade: onUpgrade)
}
)

I even did a test of my workflow and put a breakpoint there to inspect req, and it had the header I was looking for.

Describe the solution you'd like
Is it possible to add a req or headers parameter to the onUpgrade closure? Or a way to access it from the WebSocket` instance, like a new property on it?

Describe alternatives you've considered
Alternatively, I can set up my workflow to be sent via standard message as soon as the connection is upgraded (which is probably what I'll do until this is resolved), but I love for this to be integrated into the connection setup.

Thanks in advance for any help with this!

@edonv edonv added the enhancement New feature or request label Jun 20, 2024
@lmcd
Copy link

lmcd commented Jul 25, 2024

I need access to this information too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants