Skip to content

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

@edonv

Description

@edonv

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions