Skip to content

Commit

Permalink
allow virtual host style for GetBucketLocation API, if requested (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored Mar 6, 2023
1 parent 5384d69 commit 24cdd7f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 2 additions & 3 deletions bucket-cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,11 @@ func (c *Client) getBucketLocationRequest(ctx context.Context, bucketName string
}
}

isVirtualHost := s3utils.IsVirtualHostSupported(targetURL, bucketName)
isVirtualStyle := c.isVirtualHostStyleRequest(targetURL, bucketName)

var urlStr string

// only support Aliyun OSS for virtual hosted path, compatible Amazon & Google Endpoint
if isVirtualHost && s3utils.IsAliyunOSSEndpoint(targetURL) {
if isVirtualStyle {
urlStr = c.endpointURL.Scheme + "://" + bucketName + "." + targetURL.Host + "/?location"
} else {
targetURL.Path = path.Join(bucketName, "") + "/"
Expand Down
15 changes: 12 additions & 3 deletions bucket-cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,20 @@ func TestGetBucketLocationRequest(t *testing.T) {

// Set get bucket location always as path style.
targetURL := *c.endpointURL
targetURL.Path = path.Join(bucketName, "") + "/"
targetURL.RawQuery = urlValues.Encode()

isVirtualStyle := c.isVirtualHostStyleRequest(targetURL, bucketName)

var urlStr string
if isVirtualStyle {
urlStr = targetURL.Scheme + "://" + bucketName + "." + targetURL.Host + "/?location"
} else {
targetURL.Path = path.Join(bucketName, "") + "/"
targetURL.RawQuery = urlValues.Encode()
urlStr = targetURL.String()
}

// Get a new HTTP request for the method.
req, err := http.NewRequest(http.MethodGet, targetURL.String(), nil)
req, err := http.NewRequest(http.MethodGet, urlStr, nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 24cdd7f

Please sign in to comment.