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

Got panic on async connect #212

Closed
jaudiger opened this issue Feb 21, 2022 · 3 comments
Closed

Got panic on async connect #212

jaudiger opened this issue Feb 21, 2022 · 3 comments
Labels

Comments

@jaudiger
Copy link

Hi,

Since the last release of the crate, I'm beggining to have a strange panic after trying to do an async connect with the following code:

    let header = Request::builder()
        .uri("ws://localhost:5683")
        .header(http::header::SEC_WEBSOCKET_PROTOCOL, "test")
        .body(())
        .unwrap(); // Safe
    let (mut websocket_client, _) = tokio_tungstenite::connect_async(header).await.unwrap();

I got:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Protocol(InvalidHeader("sec-websocket-key"))'
@sdroege
Copy link
Contributor

sdroege commented Feb 21, 2022

You need to provide the sec-websocket-key and other headers yourself now if you create the request yourself.

Something like

        let req = Request::builder()
            .method("GET")
            .header("Host", host)
            .header("Connection", "Upgrade")
            .header("Upgrade", "websocket")
            .header("Sec-WebSocket-Version", "13")
            .header("Sec-WebSocket-Key", tungstenite::generate_key())
            .uri(self)
            .body(())?;

Or you go via your_uri.into_client_request() to get a default Request that you can then modify.

@daniel-abramov
Copy link
Member

Ok, the question seems to be answered :)

Note it's the same issue as described here.

As for the rationale, you can read the reasoning behind the change here:

@jaudiger
Copy link
Author

Yep, thanks.

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

No branches or pull requests

3 participants