From 2ceb6285e267bea649f2252f5e1c5a19b11f3d10 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Fri, 23 Aug 2024 21:28:47 +0100 Subject: [PATCH] merge with main --- .github/workflows/ci.yaml | 2 +- relay_client/src/lib.rs | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0288989..7098648 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,4 +1,4 @@ -name: ci + name: ci on: workflow_call: diff --git a/relay_client/src/lib.rs b/relay_client/src/lib.rs index 8672dcd..b890172 100644 --- a/relay_client/src/lib.rs +++ b/relay_client/src/lib.rs @@ -1,13 +1,19 @@ use { - crate::error::{ClientError, RequestBuildError}, ::http::{HeaderMap, Uri}, rand::RngCore, relay_rpc::{ + crate::error::{ClientError, RequestBuildError}, + ::http::{HeaderMap, Uri}, + rand::RngCore, + relay_rpc::{ auth::{SerializedAuthToken, RELAY_WEBSOCKET_ADDRESS}, domain::{MessageId, ProjectId, SubscriptionId}, rpc::{SubscriptionError, SubscriptionResult}, user_agent::UserAgent, - }, serde::Serialize, std::sync::{ + }, + serde::Serialize, + std::sync::{ atomic::{AtomicU8, Ordering}, Arc, - }, url::Url + }, + url::Url, }; pub mod error; @@ -180,7 +186,7 @@ pub fn generate_websocket_key() -> Result { // when decoded, is 16 bytes in length (RFC 6455) let mut rng = rand::rngs::OsRng; let mut r: [u8; 16] = [0u8; 16]; - rng.try_fill_bytes(&mut r).map_err(|err|err.to_string())?; + rng.try_fill_bytes(&mut r).map_err(|err| err.to_string())?; Ok(data_encoding::BASE64.encode(&r)) } @@ -191,11 +197,14 @@ fn into_client_request(url: &str) -> Result, RequestBuildError> let uri: Uri = url .parse() .map_err(|_| RequestBuildError::Url("Invalid url".to_owned()))?; - let authority = uri - .authority() - .ok_or(RequestBuildError::Url("Url has not authority".to_owned()))? - .as_str(); - let host = authority.split('@').last().unwrap_or_default(); + let host = { + let authority = uri + .authority() + .ok_or(RequestBuildError::Url("Url has not authority".to_owned()))? + .as_str(); + + authority.split('@').last().unwrap_or_default() + }; // Check if the host is empty (excluding the port) if host.split(':').next().unwrap_or("").is_empty() {