Skip to content

Commit

Permalink
fix(services/s3): omit default ports (apache#4379)
Browse files Browse the repository at this point in the history
* fix(services/s3): omit default ports

* remove trailing `/`
  • Loading branch information
yufan022 authored Mar 21, 2024
1 parent 4bb1d76 commit 7c3d8f8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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::*;
Expand Down Expand Up @@ -628,6 +630,12 @@ 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) {
// Remove the trailing `/` of root path.
endpoint = url.to_string().trim_end_matches('/').to_string();
}

// Update with endpoint templates.
endpoint = if let Some(template) = ENDPOINT_TEMPLATES.get(endpoint.as_str()) {
template.replace("{region}", region)
Expand Down

0 comments on commit 7c3d8f8

Please sign in to comment.