Send an Authorization HTTP header when connecting web sockets
This commit is contained in:
+10
-8
@@ -1,5 +1,6 @@
|
|||||||
use crate::{language::LanguageRegistry, worktree::Worktree};
|
use crate::{language::LanguageRegistry, worktree::Worktree};
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
|
use async_tungstenite::tungstenite::http::Request;
|
||||||
use async_tungstenite::tungstenite::{Error as WebSocketError, Message as WebSocketMessage};
|
use async_tungstenite::tungstenite::{Error as WebSocketError, Message as WebSocketMessage};
|
||||||
use gpui::{AsyncAppContext, ModelHandle, Task, WeakModelHandle};
|
use gpui::{AsyncAppContext, ModelHandle, Task, WeakModelHandle};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
@@ -91,21 +92,22 @@ impl Client {
|
|||||||
|
|
||||||
let (user_id, access_token) = Self::login(cx.platform(), &cx.background()).await?;
|
let (user_id, access_token) = Self::login(cx.platform(), &cx.background()).await?;
|
||||||
let user_id = user_id.parse()?;
|
let user_id = user_id.parse()?;
|
||||||
|
let request =
|
||||||
|
Request::builder().header("Authorization", format!("{} {}", user_id, access_token));
|
||||||
|
|
||||||
if let Some(host) = ZED_SERVER_URL.strip_prefix("https://") {
|
if let Some(host) = ZED_SERVER_URL.strip_prefix("https://") {
|
||||||
let stream = smol::net::TcpStream::connect(host).await?;
|
let stream = smol::net::TcpStream::connect(host).await?;
|
||||||
let (stream, _) = async_tungstenite::async_tls::client_async_tls(
|
let request = request.uri(format!("wss://{}/rpc", host)).body(())?;
|
||||||
format!("wss://{}/rpc", host),
|
let (stream, _) = async_tungstenite::async_tls::client_async_tls(request, stream)
|
||||||
stream,
|
.await
|
||||||
)
|
.context("websocket handshake")?;
|
||||||
.await
|
|
||||||
.context("websocket handshake")?;
|
|
||||||
log::info!("connected to rpc address {}", *ZED_SERVER_URL);
|
log::info!("connected to rpc address {}", *ZED_SERVER_URL);
|
||||||
self.add_connection(stream, user_id, access_token, router, cx)
|
self.add_connection(stream, user_id, access_token, router, cx)
|
||||||
.await?;
|
.await?;
|
||||||
} else if let Some(host) = ZED_SERVER_URL.strip_prefix("http://") {
|
} else if let Some(host) = ZED_SERVER_URL.strip_prefix("http://") {
|
||||||
let stream = smol::net::TcpStream::connect(host).await?;
|
let stream = smol::net::TcpStream::connect(host).await?;
|
||||||
let (stream, _) =
|
let request = request.uri(format!("ws://{}/rpc", host)).body(())?;
|
||||||
async_tungstenite::client_async(format!("ws://{}/rpc", host), stream).await?;
|
let (stream, _) = async_tungstenite::client_async(request, stream).await?;
|
||||||
log::info!("connected to rpc address {}", *ZED_SERVER_URL);
|
log::info!("connected to rpc address {}", *ZED_SERVER_URL);
|
||||||
self.add_connection(stream, user_id, access_token, router, cx)
|
self.add_connection(stream, user_id, access_token, router, cx)
|
||||||
.await?;
|
.await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user