From b05136e173f83f3c59280501a3fd4b04f7356e6f Mon Sep 17 00:00:00 2001 From: th4s Date: Thu, 10 Mar 2022 22:36:42 +0100 Subject: [PATCH] Fix websocket connection request (#1005) In tungstenite 0.17 a change was introduced considering the logic of `IntoClientRequest`. When using this trait on a `HttpRequest` it just uses the request without any changes to inititate the websocket connection. This makes it necessary for the consumer of the api to supply the correct http headers for initiating a websocket connection when using `IntoClientRequest` on `HttpRequest`. This commit adapts the logic in `connect_with_auth` to this new behavior. --- ethers-providers/src/transports/ws.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/ethers-providers/src/transports/ws.rs b/ethers-providers/src/transports/ws.rs index ba27729b..31306e54 100644 --- a/ethers-providers/src/transports/ws.rs +++ b/ethers-providers/src/transports/ws.rs @@ -62,8 +62,7 @@ if_not_wasm! { use super::Authorization; use tracing::{debug, error, warn}; use http::Request as HttpRequest; - use http::Uri; - use std::str::FromStr; + use tungstenite::client::IntoClientRequest; } type Pending = oneshot::Sender>; @@ -137,9 +136,7 @@ impl Ws { /// Initializes a new WebSocket Client #[cfg(not(target_arch = "wasm32"))] - pub async fn connect( - url: impl tungstenite::client::IntoClientRequest + Unpin, - ) -> Result { + pub async fn connect(url: impl IntoClientRequest + Unpin) -> Result { let (ws, _) = connect_async(url).await?; Ok(Self::new(ws)) } @@ -147,11 +144,10 @@ impl Ws { /// Initializes a new WebSocket Client with authentication #[cfg(not(target_arch = "wasm32"))] pub async fn connect_with_auth( - uri: impl AsRef + Unpin, + uri: impl IntoClientRequest + Unpin, auth: Authorization, ) -> Result { - let mut request: HttpRequest<()> = - HttpRequest::builder().method("GET").uri(Uri::from_str(uri.as_ref())?).body(())?; + let mut request: HttpRequest<()> = uri.into_client_request()?; let mut auth_value = http::HeaderValue::from_str(&auth.to_string())?; auth_value.set_sensitive(true);