chiark / gitweb /
Don't put '?' on the end of parameterless URLs.
authorSimon Tatham <anakin@pobox.com>
Sun, 31 Dec 2023 15:00:07 +0000 (15:00 +0000)
committerSimon Tatham <anakin@pobox.com>
Sun, 31 Dec 2023 15:00:07 +0000 (15:00 +0000)
If you call reqwest::Url::parse_with_params and give it an empty
parameter iterator, it still appends '?' to the URL, and then doesn't
put anything after it.

I don't _think_ that actually makes any difference, but it looks ugly.
More to the point, I noticed it while pasting HTTP transcripts to
report a bug in the Mastodon dev setup, and thought I'd better try
again without the spurious '?', in case it did make a difference.

src/client.rs

index 0a7cdfa90df3d5a222421cf3f02bb69d61ad5d9d..a9b4e035c8ed2afcbbbbacf4003bc956b5e245e8 100644 (file)
@@ -184,7 +184,12 @@ impl Client {
 
         let urlstr = self.auth.instance_url.clone() + "/api/v1/" +
             &req.url_suffix;
-        let url = match Url::parse_with_params(&urlstr, req.parameters.iter()) {
+        let parsed = if req.parameters.is_empty() {
+            Url::parse(&urlstr)
+        } else {
+            Url::parse_with_params(&urlstr, req.parameters.iter())
+        };
+        let url = match parsed {
             Ok(url) => Ok(url),
             Err(e) => Err(ClientError::UrlParseError(
                urlstr.clone(), e.to_string())),