Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow establishing of websocket with web optional protocols parameter #107

Open
jadedevin13 opened this issue Feb 11, 2020 · 3 comments
Open

Comments

@jadedevin13
Copy link

jadedevin13 commented Feb 11, 2020

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

@rofrol
Copy link

rofrol commented Feb 11, 2020

Above example does not use optional parameter

@Voronar
Copy link
Contributor

Voronar commented Aug 26, 2020

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

@daniel-abramov
Copy link
Member

Current state: #145 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants