tungstenite-rs icon indicating copy to clipboard operation
tungstenite-rs copied to clipboard

Allow establishing of websocket with web optional protocols parameter

Open jadedevin13 opened this issue 4 years ago • 3 comments

cargo run --example server

  1. Open web browser dev console.

  2. Use ws and not secure wss, otherwise I get invalid token.

  3. Run this:

    var exampleSocket = new WebSocket("ws://www.example.com/socketserver", "sip");
    
  4. 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

jadedevin13 avatar Feb 11 '20 18:02 jadedevin13

Above example does not use optional parameter

rofrol avatar Feb 11 '20 19:02 rofrol

@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());
});

Voronar avatar Aug 26 '20 12:08 Voronar

Current state: https://github.com/snapview/tungstenite-rs/issues/145#issuecomment-713581499

daniel-abramov avatar Oct 21 '20 13:10 daniel-abramov