Skip to content

Commit

Permalink
Fix for servers responding partial URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
YDX-2147483647 committed Aug 27, 2023
1 parent 82c3a89 commit 35ec2f8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/action/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,21 @@ impl UploadResponse {
key: &KeySet,
expiry_time: Option<DateTime<Utc>>,
) -> Result<RemoteFile, UploadError> {
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),
))
Expand Down

0 comments on commit 35ec2f8

Please sign in to comment.