Skip to content

Commit

Permalink
fix: client URL parsing (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
heilhead committed Mar 16, 2023
1 parent ced99e7 commit 7f08502
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions relay_client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ tokio-stream = "0.1"
tokio-util = "0.7"
pin-project = "1.0"
chrono = { version = "0.4", default-features = false, features = ["alloc", "std"] }
url = "2.3"
3 changes: 3 additions & 0 deletions relay_client/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ pub enum RequestBuildError {
#[error("Failed to add request headers")]
Headers,

#[error("Failed to parse connection URL: {0}")]
Url(#[from] url::ParseError),

#[error("Failed to create websocket request: {0}")]
Other(WsError),
}
Expand Down
6 changes: 5 additions & 1 deletion relay_client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use {
},
serde::Serialize,
tokio_tungstenite::tungstenite::{client::IntoClientRequest, http},
url::Url,
};

mod client;
Expand Down Expand Up @@ -102,7 +103,10 @@ impl ConnectionOptions {
serde_qs::to_string(&query).map_err(RequestBuildError::Query)?
};

let mut request = format!("{address}/?{query}")
let mut url = Url::parse(&address).map_err(RequestBuildError::Url)?;
url.set_query(Some(&query));

let mut request = url
.into_client_request()
.map_err(RequestBuildError::Other)?;

Expand Down

0 comments on commit 7f08502

Please sign in to comment.