From 7640c03c1e2487f6ba9f86c309b569e742ead901 Mon Sep 17 00:00:00 2001 From: phil Date: Sat, 4 Oct 2025 16:48:47 -0400 Subject: [PATCH] construct the URI path and query via typed Url this probably either does too much or too little: - could have fixed the double-slash thing by stripping trailing slash from the base uri or, - if you like typed URLs, it probably makes sense to do a bigger refactor toward them. ...sidestepping adding the actual `url` dependency by using the one included with `reqwest`. maybe this is not what you want. currently using `EncodeError::Other` instead of adding a variant to `EncodeError` itself because the parse error comes from `Url`, which we snuck in from `reqwest`, which isn't a dependency of the `-common` crate. --- crates/jacquard/src/client.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/jacquard/src/client.rs b/crates/jacquard/src/client.rs index 0c857fb..2fd74b9 100644 --- a/crates/jacquard/src/client.rs +++ b/crates/jacquard/src/client.rs @@ -10,7 +10,7 @@ use std::fmt::Display; use std::future::Future; use bytes::Bytes; -pub use error::{ClientError, Result}; +pub use error::{ClientError, Result, TransportError}; use http::{ HeaderName, HeaderValue, Request, header::{AUTHORIZATION, CONTENT_TYPE, InvalidHeaderValue}, @@ -152,15 +152,18 @@ where R: XrpcRequest, C: XrpcClient + ?Sized, { - // Build URI: base_uri + /xrpc/ + NSID - let mut uri = format!("{}/xrpc/{}", client.base_uri(), R::NSID); + // Configure the XRPC endpoint + let mut url: reqwest::Url = client + .base_uri() + .parse() + .map_err(|e| error::EncodeError::Other(format!("failed to parse base_uri: {e}").into()))?; + url.set_path(&format!("/xrpc/{}", R::NSID)); // Add query parameters for Query methods if let XrpcMethod::Query = R::METHOD { let qs = serde_html_form::to_string(&request).map_err(error::EncodeError::from)?; if !qs.is_empty() { - uri.push('?'); - uri.push_str(&qs); + url.set_query(Some(&qs)) } } @@ -170,7 +173,7 @@ where XrpcMethod::Procedure(_) => http::Method::POST, }; - let mut builder = Request::builder().method(method).uri(&uri); + let mut builder = Request::builder().method(method).uri(&url.to_string()); // Add Content-Type for procedures if let XrpcMethod::Procedure(encoding) = R::METHOD { -- 2.43.0