Closed simbleau closed 1 year ago
I'll look into this tonight after work.
The library wraps the existing javascript API for WebSockets. From what I gather (I admit I haven't really played with this myself), you can pass a header to the protocols
parameter. This takes an Option<Vec<&str>>
in rust and you can see an example (in Js) here:
https://stackoverflow.com/questions/22383089/is-it-possible-to-use-bearer-authentication-for-websocket-upgrade-requests
Let me know if this solves your issue.
You can obviously also allow the connection first and implement your authentication manually: https://websockets.readthedocs.io/en/stable/topics/authentication.html
This document states:
Setting a custom HTTP header
This would be the most elegant mechanism, solving all issues with the options discussed above.
Unfortunately, it doesn’t work because the WebSocket API doesn’t support setting custom headers.
Some more discussion here: https://github.com/whatwg/websockets/issues/16
It looks like what you want does not have great support in websockets. You'll have to do some research to see what's the best solution. If ws_stream_wasm
can really be improved here, feel free to post more feedback, but I would like to avoid custom rolling stuff in this library. It's just a rust idiomatic wrapper around the Js API. You can always wrap the WsMeta
type in a newtype to give it extra functionality on top.
Yep, fair call.
I can't find the ability to attach headers on
WsMeta::connect
, is there no way to do Basic Authentication or Bearer authentication? :)