Skip to content

Commit 563b3c7

Browse files
committed
Allow altenate endpoint such as 'http://s3/bucket/key'.
1 parent 53357d7 commit 563b3c7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

util.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func EndpointRegionBucketKey(address *url.URL) (endpoint, region, bucket, key st
2727
bucket, key = BucketKey(address)
2828
if address != nil {
2929
region = extractRegion(address.Host)
30-
if !strings.Contains(address.Host, "s3") {
30+
if isAlternateEndpoint(address.Host) {
3131
endpoint = address.Scheme + "://" + address.Host
3232
}
3333
}
@@ -55,8 +55,11 @@ func BucketKey(address *url.URL) (bucket, key string) {
5555
return bucket, key
5656
}
5757

58+
func isAlternateEndpoint(host string) bool {
59+
return !strings.HasSuffix(host, ".amazonaws.com")
60+
}
5861
func isPathStyleAddress(host string) bool {
59-
return !strings.Contains(host, "s3") || strings.HasPrefix(host, "s3.") || strings.HasPrefix(host, "s3-")
62+
return isAlternateEndpoint(host) || strings.HasPrefix(host, "s3.") || strings.HasPrefix(host, "s3-")
6063
}
6164

6265
func extractVirtualBucket(host string) string {

util_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func (this *ParsingFixture) Test() {
4141
this.assertFields(URL("//s3-region.amazonaws.com/bucket/key"), "", "region", "bucket", "key")
4242
this.assertFields(URL("//bucket.s3.amazonaws.com/key"), "", "", "bucket", "key")
4343
this.assertFields(URL("//bucket.s3-region.amazonaws.com/key"), "", "region", "bucket", "key")
44+
this.assertFields(URL("//s3/bucket/key"), "https://s3", "", "bucket", "key")
4445
this.assertFields(URL("//localhost/bucket/key"), "https://localhost", "", "bucket", "key")
4546
this.assertFields(URL("//1.2.3.4:5678/bucket/key"), "https://1.2.3.4:5678", "", "bucket", "key")
4647
}

0 commit comments

Comments
 (0)