Skip to content

Commit e2a8659

Browse files
ericdong66tgross
authored andcommitted
Add support to detect 5 parts s3 virtual hosted-style requests
1 parent 7b99c31 commit e2a8659

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

detect_s3.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func (d *S3Detector) detectHTTP(src string) (string, bool, error) {
3434
return d.detectPathStyle(hostParts[0], parts[1:])
3535
} else if len(hostParts) == 4 {
3636
return d.detectVhostStyle(hostParts[1], hostParts[0], parts[1:])
37+
} else if len(hostParts) == 5 && hostParts[1] == "s3" {
38+
return d.detectNewVhostStyle(hostParts[2], hostParts[0], parts[1:])
3739
} else {
3840
return "", false, fmt.Errorf(
3941
"URL is not a valid S3 URL")
@@ -59,3 +61,13 @@ func (d *S3Detector) detectVhostStyle(region, bucket string, parts []string) (st
5961

6062
return "s3::" + url.String(), true, nil
6163
}
64+
65+
func (d *S3Detector) detectNewVhostStyle(region, bucket string, parts []string) (string, bool, error) {
66+
urlStr := fmt.Sprintf("https://s3.%s.amazonaws.com/%s/%s", region, bucket, strings.Join(parts, "/"))
67+
url, err := url.Parse(urlStr)
68+
if err != nil {
69+
return "", false, fmt.Errorf("error parsing S3 URL: %s", err)
70+
}
71+
72+
return "s3::" + url.String(), true, nil
73+
}

detect_s3_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ func TestS3Detector(t *testing.T) {
3434
"bucket.s3-eu-west-1.amazonaws.com/foo/bar.baz",
3535
"s3::https://s3-eu-west-1.amazonaws.com/bucket/foo/bar.baz",
3636
},
37+
// 5 parts Virtual hosted-style
38+
{
39+
"bucket.s3.eu-west-1.amazonaws.com/foo/bar.baz",
40+
"s3::https://s3.eu-west-1.amazonaws.com/bucket/foo/bar.baz",
41+
},
3742
// Path style
3843
{
3944
"s3.amazonaws.com/bucket/foo",

0 commit comments

Comments
 (0)