diff --git a/src/lib.rs b/src/lib.rs index c0cbf46..cb04f79 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,7 +76,16 @@ fn make_request( let mut parts = base.into_parts(); parts.path_and_query = Some( match parts.path_and_query { - Some(path) => format!("{}{}", path, path_suffix).try_into(), + Some(path_and_query) => { + let mut path = path_and_query.path().to_owned(); + if !path.ends_with('/') { + path.push('/'); + } + path += path_suffix; + + // Drop query parameters + path.try_into() + } None => path_suffix.try_into(), } .expect("api_uri path"), diff --git a/src/tests.rs b/src/tests.rs index cdbd910..bd9ffbd 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1342,3 +1342,17 @@ async fn get_package_release_ok() { } ) } + +#[test] +fn make_request_base_trailing_slash_is_optional() { + let slash = http::Uri::from_static("http://host/path/"); + let no_slash = http::Uri::from_static("http://host/path"); + let suffix = "suffix"; + let expect = "/path/suffix"; + + let slash = make_request(slash, http::Method::GET, suffix, None); + assert_eq!(slash.uri_ref().unwrap().path(), expect); + + let no_slash = make_request(no_slash, http::Method::GET, suffix, None); + assert_eq!(no_slash.uri_ref().unwrap().path(), expect); +}