From 2bfd46d48c350358e74e151250ac9cf9dfef05f2 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Wed, 26 Oct 2022 16:04:55 -0700 Subject: [PATCH] Fix setting of preview param in RPC URL --- crates/client/src/client.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 4c468059ff72fe805eedace13eaee681fe233b39..c4a3167f83e2aefb9276454b8cf27777960c94b2 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -932,8 +932,9 @@ impl Client { self.establish_websocket_connection(credentials, cx) } - async fn get_rpc_url(http: Arc) -> Result { - let url = format!("{}/rpc", *ZED_SERVER_URL); + async fn get_rpc_url(http: Arc, is_preview: bool) -> Result { + let preview_param = if is_preview { "?preview=1" } else { "" }; + let url = format!("{}/rpc{preview_param}", *ZED_SERVER_URL); let response = http.get(&url, Default::default(), false).await?; // Normally, ZED_SERVER_URL is set to the URL of zed.dev website. @@ -985,13 +986,12 @@ impl Client { let http = self.http.clone(); cx.background().spawn(async move { - let mut rpc_url = Self::get_rpc_url(http).await?; + let mut rpc_url = Self::get_rpc_url(http, is_preview).await?; let rpc_host = rpc_url .host_str() .zip(rpc_url.port_or_known_default()) .ok_or_else(|| anyhow!("missing host in rpc url"))?; let stream = smol::net::TcpStream::connect(rpc_host).await?; - rpc_url.set_query(if is_preview { Some("preview=1") } else { None }); log::info!("connected to rpc endpoint {}", rpc_url); @@ -1140,7 +1140,7 @@ impl Client { // Use the collab server's admin API to retrieve the id // of the impersonated user. - let mut url = Self::get_rpc_url(http.clone()).await?; + let mut url = Self::get_rpc_url(http.clone(), false).await?; url.set_path("/user"); url.set_query(Some(&format!("github_login={login}"))); let request = Request::get(url.as_str())