You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there! From the latest version on I get a regression when connecting with a http::Request. In version 0.17.1 I get an WebsocketError(Protocol(InvalidHeader("sec-websocket-key"))) error when connecting via a Request, which worked back in earlier versions. Some example code to trigger the error (using tokio-tungstenite):
I looked into the issue and found out that the changes of PR #259 changed behavior for checking the key for a requests. In version 0.16.0 every request's sec-websocket-key header was set:
let authority = self.authority().ok_or(Error::Url(UrlError::NoHostName))?.as_str();
let host = authority
.find('@')
.map(|idx| authority.split_at(idx + 1).1)
.unwrap_or_else(|| authority);
if host.is_empty(){
returnErr(Error::Url(UrlError::EmptyHostName));
}
let req = Request::builder()
.method("GET")
.header("Host", host)
.header("Connection","Upgrade")
.header("Upgrade","websocket")
.header("Sec-WebSocket-Version","13")
.header("Sec-WebSocket-Key",generate_key())
.uri(self)
.body(())?;
Ok(req)
}
}
But not for a http::Request. A possible solution would be to add the sec-websocket-key header in the implementation of IntoClientRequest, in case it is not yet present on a Request. Or is the intention that the user should provide it's own key when using a http::Request for connection?
The text was updated successfully, but these errors were encountered:
Essentially, if you're just simply using the tungstenite, e.g. you want to connect to an endpoint and use WebSockets, you could simply pass the URI and rely on the IntoClientRequest implementation that takes care of generating all required headers. But not when we receive http::Request, in which case we simply "pass-through" the request (after verifying that it's a correct request). Some rationale could be found here.
Or is the intention that the user should provide its key when using a http::Request for connection?
Depends on your use case. If there is no strong reason to create a custom http::Request, you could simply pass &str and benefit from tungstenite generating headers for you. In case you want to benefit from tungstenite generation of headers, but alter some of them, this could be a solution: #264 (comment)
Hi there! From the latest version on I get a regression when connecting with a
http::Request
. In version 0.17.1 I get anWebsocketError(Protocol(InvalidHeader("sec-websocket-key")))
error when connecting via a Request, which worked back in earlier versions. Some example code to trigger the error (using tokio-tungstenite):I looked into the issue and found out that the changes of PR #259 changed behavior for checking the key for a requests. In version 0.16.0 every request's
sec-websocket-key
header was set:tungstenite-rs/src/handshake/client.rs
Lines 55 to 65 in 958fdb9
But the changes of PR #259 changed the behavior and now expect the
sec-websocket-key
header on every request:tungstenite-rs/src/handshake/client.rs
Lines 97 to 122 in 45dad40
This is fine for passing in a
Uri
or aString
as theIntoClientRequest
implementation covers the conversion:tungstenite-rs/src/client.rs
Lines 215 to 238 in 45dad40
But not for a
http::Request
. A possible solution would be to add thesec-websocket-key
header in the implementation ofIntoClientRequest
, in case it is not yet present on a Request. Or is the intention that the user should provide it's own key when using ahttp::Request
for connection?The text was updated successfully, but these errors were encountered: