From 88f14e3375f85eda88386a7809a9364ceb54f145 Mon Sep 17 00:00:00 2001 From: yufan Date: Tue, 19 Mar 2024 02:02:57 +0800 Subject: [PATCH 1/2] fix(services/s3): omit default ports --- core/src/services/s3/backend.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs index bb7b3949c383..610618f75e15 100644 --- a/core/src/services/s3/backend.rs +++ b/core/src/services/s3/backend.rs @@ -19,6 +19,7 @@ use std::collections::HashMap; use std::fmt::Debug; use std::fmt::Formatter; use std::fmt::Write; +use std::str::FromStr; use std::sync::atomic::AtomicBool; use std::sync::Arc; @@ -37,6 +38,7 @@ use reqsign::AwsConfig; use reqsign::AwsCredentialLoad; use reqsign::AwsDefaultLoader; use reqsign::AwsV4Signer; +use reqwest::Url; use serde::Deserialize; use super::core::*; @@ -628,6 +630,11 @@ impl S3Builder { // If endpoint contains bucket name, we should trim them. endpoint = endpoint.replace(&format!("//{bucket}."), "//"); + // Omit default ports if specified. + if let Ok(url) = Url::from_str(&endpoint) { + endpoint = url.to_string(); + } + // Update with endpoint templates. endpoint = if let Some(template) = ENDPOINT_TEMPLATES.get(endpoint.as_str()) { template.replace("{region}", region) From cd650809c8aceffd5d9e493073afc8845b848141 Mon Sep 17 00:00:00 2001 From: yufan Date: Tue, 19 Mar 2024 23:33:12 +0800 Subject: [PATCH 2/2] remove trailing `/` --- core/src/services/s3/backend.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs index 610618f75e15..a9853a82f3e3 100644 --- a/core/src/services/s3/backend.rs +++ b/core/src/services/s3/backend.rs @@ -632,7 +632,8 @@ impl S3Builder { // Omit default ports if specified. if let Ok(url) = Url::from_str(&endpoint) { - endpoint = url.to_string(); + // Remove the trailing `/` of root path. + endpoint = url.to_string().trim_end_matches('/').to_string(); } // Update with endpoint templates.