Add ability to provide custom sec-websocket-protocol
header
#147
Labels
enhancement
New feature or request
sec-websocket-protocol
header
#147
What is the problem this feature would solve?
The WebSocket browser API is a bit broken, and annoyingly doesn't support passing custom headers. I've done a lot of research, and it seems the most secure and efficient way to handle authentication with websockets is smuggling authentication tokens in the
sec-websocket-protocol
header. Browsers support this as the second parameter to the WebSocket constructor, i.e.const ws = new WebSocket("wss://localhost:3000/ws", [authToken]);
.I managed to implement this in my Elysia backend, but my hurdle to using Treaty is this method isn't supported, as supplying custom headers entirely isn't supported by the browsers. This however would be very simple to add.
What is the feature you are proposing to solve the problem?
Add a third parameter to
Treaty.Create.subscribe
,protocols: string[]
, which would be passed into the internal WebSocket constructor's second argument.What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: