From bdd4a63a8d19c3afeb62f75c5c792c033999e50a Mon Sep 17 00:00:00 2001 From: shockrah Date: Fri, 9 Apr 2021 21:52:57 -0700 Subject: [PATCH] * Fixing url construction for websockets --- tui/src/net.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tui/src/net.rs b/tui/src/net.rs index d3a73e0..8188e99 100644 --- a/tui/src/net.rs +++ b/tui/src/net.rs @@ -4,8 +4,6 @@ use reqwest::{Client, Url, Body, Response}; use reqwest::header::{HeaderMap, HeaderValue, CONTENT_TYPE}; use reqwest::Result as HttpResult; -// TODO: Url generation is kinda gross looking but i'm not 100% -// convinced it needs to be pretty if its just going to add overhead pub async fn login(url: &str, id: u64, secret: &str) -> HttpResult { let client = Client::new(); @@ -55,5 +53,11 @@ pub async fn send_text<'m>(url: &str, id: u64, jwt: &str, chan: u64, msg: &str) Ok(client.post(url).body(body).headers(headers).send().await?) } -pub async fn setup_websocket(url: &str) { +pub fn ws_url(base: &str, jwt: Option) -> String { + let base = format!("{}/text", base); + let jwt = jwt.unwrap_or("hehexd".into()); + let mut url = Url::parse_with_params(base.as_ref(), &[("jwt", jwt.as_str())]).unwrap(); + let _ = url.set_port(Some(5648)); + let _ = url.set_scheme("ws"); + url.to_string() }