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.
This commit is contained in:
parent
1b1cde0ee3
commit
b05136e173
|
@ -62,8 +62,7 @@ if_not_wasm! {
|
||||||
use super::Authorization;
|
use super::Authorization;
|
||||||
use tracing::{debug, error, warn};
|
use tracing::{debug, error, warn};
|
||||||
use http::Request as HttpRequest;
|
use http::Request as HttpRequest;
|
||||||
use http::Uri;
|
use tungstenite::client::IntoClientRequest;
|
||||||
use std::str::FromStr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Pending = oneshot::Sender<Result<serde_json::Value, JsonRpcError>>;
|
type Pending = oneshot::Sender<Result<serde_json::Value, JsonRpcError>>;
|
||||||
|
@ -137,9 +136,7 @@ impl Ws {
|
||||||
|
|
||||||
/// Initializes a new WebSocket Client
|
/// Initializes a new WebSocket Client
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub async fn connect(
|
pub async fn connect(url: impl IntoClientRequest + Unpin) -> Result<Self, ClientError> {
|
||||||
url: impl tungstenite::client::IntoClientRequest + Unpin,
|
|
||||||
) -> Result<Self, ClientError> {
|
|
||||||
let (ws, _) = connect_async(url).await?;
|
let (ws, _) = connect_async(url).await?;
|
||||||
Ok(Self::new(ws))
|
Ok(Self::new(ws))
|
||||||
}
|
}
|
||||||
|
@ -147,11 +144,10 @@ impl Ws {
|
||||||
/// Initializes a new WebSocket Client with authentication
|
/// Initializes a new WebSocket Client with authentication
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub async fn connect_with_auth(
|
pub async fn connect_with_auth(
|
||||||
uri: impl AsRef<str> + Unpin,
|
uri: impl IntoClientRequest + Unpin,
|
||||||
auth: Authorization,
|
auth: Authorization,
|
||||||
) -> Result<Self, ClientError> {
|
) -> Result<Self, ClientError> {
|
||||||
let mut request: HttpRequest<()> =
|
let mut request: HttpRequest<()> = uri.into_client_request()?;
|
||||||
HttpRequest::builder().method("GET").uri(Uri::from_str(uri.as_ref())?).body(())?;
|
|
||||||
|
|
||||||
let mut auth_value = http::HeaderValue::from_str(&auth.to_string())?;
|
let mut auth_value = http::HeaderValue::from_str(&auth.to_string())?;
|
||||||
auth_value.set_sensitive(true);
|
auth_value.set_sensitive(true);
|
||||||
|
|
Loading…
Reference in New Issue