From 35ec2f80f98e190e22cc687b75fde8d3c99ff48d Mon Sep 17 00:00:00 2001 From: "Y.D.X." <73375426+YDX-2147483647@users.noreply.github.com> Date: Sun, 27 Aug 2023 12:36:53 +0800 Subject: [PATCH] Fix for servers responding partial URLs Fixes timvisee/ffsend#159 --- src/action/upload.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/action/upload.rs b/src/action/upload.rs index 6880cea..e3ea8a1 100644 --- a/src/action/upload.rs +++ b/src/action/upload.rs @@ -454,12 +454,21 @@ impl UploadResponse { key: &KeySet, expiry_time: Option>, ) -> Result { + let url = Url::parse(&self.url).or_else(|err| { + if err == UrlParseError::RelativeUrlWithoutBase { + // Some server responds with a URL without scheme, or even a relative URL + if let Some(domain) = &host.domain() { + return host.join(self.url.strip_prefix(domain).unwrap_or(&self.url)); + } + } + Err(err) + })?; Ok(RemoteFile::new( self.id, Some(Utc::now()), expiry_time, host, - Url::parse(&self.url)?, + url, key.secret().to_vec(), Some(self.owner_token), ))