Skip to content

Commit 849664a

Browse files
authored
fix url split path
fix for url split slash
1 parent 6ea6beb commit 849664a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/v1/api.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -782,15 +782,19 @@ impl OpenAIClient {
782782
self.get(&url).await
783783
}
784784
fn build_url_with_preserved_query(&self, path: &str) -> Result<String, url::ParseError> {
785-
let base = Url::parse(&self.api_endpoint)?;
786-
let mut url = base.join(path)?;
785+
let (base, query_opt) = match self.api_endpoint.split_once('?') {
786+
Some((b, q)) => (b.trim_end_matches('/'), Some(q)),
787+
None => (self.api_endpoint.trim_end_matches('/'), None),
788+
};
789+
790+
let full_path = format!("{}/{}", base, path.trim_start_matches('/'));
791+
let mut url = Url::parse(&full_path)?;
787792

788-
if let Some(q) = base.query() {
789-
for (k, v) in url::form_urlencoded::parse(q.as_bytes()) {
793+
if let Some(query) = query_opt {
794+
for (k, v) in url::form_urlencoded::parse(query.as_bytes()) {
790795
url.query_pairs_mut().append_pair(&k, &v);
791796
}
792797
}
793-
794798
Ok(url.to_string())
795799
}
796800
fn query_params(

0 commit comments

Comments
 (0)