tungstenite-rs
tungstenite-rs copied to clipboard
Allow establishing of websocket with web optional protocols parameter
cargo run --example server
-
Open web browser dev console.
-
Use ws and not secure wss, otherwise I get invalid token.
-
Run this:
var exampleSocket = new WebSocket("ws://www.example.com/socketserver", "sip");
-
Error:
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Protocol("Connection reset without closing handshake")', src/libcore/result.rs:1165:5
Reference https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/WebSocket
Above example does not use optional parameter
@jadedevin13 I use connection callback (https://github.com/snapview/tungstenite-rs/blob/master/examples/server.rs#L12) as workaround:
req.headers().get("sec-websocket-protocol").map(|sp| {
let headers = resp.headers_mut();
headers.append("sec-websocket-protocol", sp.clone());
});
Current state: https://github.com/snapview/tungstenite-rs/issues/145#issuecomment-713581499