diff --git a/client/src/http_default.rs b/client/src/http_default.rs index 7229d35f768..727672308d2 100644 --- a/client/src/http_default.rs +++ b/client/src/http_default.rs @@ -8,6 +8,7 @@ use eyre::{eyre, Error, Result, WrapErr}; use http::header::HeaderName; use tokio_tungstenite::tungstenite::{stream::MaybeTlsStream, WebSocket}; pub use tokio_tungstenite::tungstenite::{Error as WebSocketError, Message as WebSocketMessage}; +use tokio_tungstenite::tungstenite::client::IntoClientRequest; use url::Url; use crate::http::{Method, RequestBuilder, Response}; @@ -117,21 +118,13 @@ impl DefaultWebSocketRequestBuilder { /// Consumes itself to build request. pub fn build(self) -> Result { - let mut req = self.0.and_then(|b| b.body(()).map_err(Into::into))?; - - let uri = req.uri().to_string(); - let headers = req.headers_mut(); - - headers.insert("Host", uri.parse()?); - headers.insert("Connection", "Upgrade".parse()?); - headers.insert("Upgrade", "websocket".parse()?); - headers.insert("Sec-WebSocket-Version", "13".parse()?); - headers.insert( - "Sec-WebSocket-Key", - tokio_tungstenite::tungstenite::handshake::client::generate_key().parse()?, - ); - - Ok(DefaultWebSocketStreamRequest(req)) + let builder = self.0?; + let mut request = builder.uri_ref().ok_or(eyre!("Missing URI"))?.into_client_request()?; + if let Some(auth_header) = builder.headers_ref() + .ok_or(eyre!("No headers found"))?.get("Authorization") { + request.headers_mut().insert("Authorization", auth_header.clone()); + } + Ok(DefaultWebSocketStreamRequest(request)) } }