Preserve the original S3 endpoint scheme

This commit is contained in:
Sven Skender
2026-06-17 15:45:08 +02:00
parent fd0f0657b9
commit 19af0b65cc
3 changed files with 24 additions and 3 deletions
+8
View File
@@ -70,21 +70,29 @@ func ParseURL(s3URL string) (*Config, error) {
return nil, fmt.Errorf("s3: region query parameter is required")
}
endpointParam := u.Query().Get("endpoint")
var scheme string
var endpoint string
var pathStyle bool
if endpointParam != "" {
// Custom endpoint: strip scheme prefix to extract host[:port]
uep, err := url.Parse(endpointParam)
if err != nil {
return nil, fmt.Errorf("s3: invalid endpoint URL: %w", err)
}
scheme = uep.Scheme
ep := strings.TrimRight(endpointParam, "/")
ep = strings.TrimPrefix(ep, "https://")
ep = strings.TrimPrefix(ep, "http://")
endpoint = ep
pathStyle = true
} else {
scheme = "https"
endpoint = fmt.Sprintf("s3.%s.amazonaws.com", region)
pathStyle = false
}
disableHTTP2, _ := strconv.ParseBool(u.Query().Get("disable_http2"))
return &Config{
Scheme: scheme,
Endpoint: endpoint,
PathStyle: pathStyle,
Bucket: bucket,