snapview / tokio-tungstenite

Future-based Tungstenite for Tokio. Lightweight stream-based WebSocket implementation
MIT License
1.88k stars 236 forks source link

MissingConnectionUpgrade when connecting from wss client #216

Closed trampster closed 2 years ago

trampster commented 2 years ago

When I try to do it with the following:

tokio_tungstenite::connect_async_with_config(
        format!("{}websocket?token={}",
        wss_target_url, subscribe_response.token),
        Some(tokio_tungstenite::tungstenite::protocol::WebSocketConfig {
            max_send_queue: Some(target_cnf.performance.websocket_send_queue_limit),
            max_message_size: None, // unlimited
            max_frame_size: None,  // unlimited
        })
    )
    .await
    .with_context(|| format!("failure to connect to"))?;

With this in my cargo.toml

tokio-tungstenite = { version = "0.11.0", features = ["tls"] }

Then I get this error (serverside):

warp::filters::trace: unable to serve request (client error) status=400 error Rejection([MissingConnectionUpgrade, MethodNotAllowed, MethodNotAllowed])

Googling indicates that there should be a upgrade header telling the server to upgrade the https connection to the websocket. But for some reason it is missing.

daniel-abramov commented 2 years ago

You are using the tls feature, but there is no such feature, try to use native-tls or rustls-tls-webpki-roots or other TLS features (depending on your requirements) and I think it would allow you to get the behavior you expect 😉

See Features section for more details.

trampster commented 2 years ago

With: tokio-tungstenite = { version = "0.11.0", features = ["native-tls"] }

I get "URL error: TLS support not compiled in"

daniel-abramov commented 2 years ago

Ah sorry, I did not notice you used the version 0.11.0, it's a very old version. The current version is 0.17.1, could you try with it?

NB: Version 0.11.0 should work with tls feature though. Not sure why it fails. Do you have a SSCCE that could be used to verify the issue?