Skip to content

Commit

Permalink
Listbuckets API: Retry with region returned by s3 server (#1113)
Browse files Browse the repository at this point in the history
In case of AuthorizationHeaderMalformed error, retry with the region
returned by the S3 server.

This allows listBuckets to work with S3 servers that does not support
signing with us-east-1 by default
  • Loading branch information
kannappanr authored May 29, 2019
1 parent 952dac3 commit 1726b1f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api-list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ import (
func (c Client) ListBuckets() ([]BucketInfo, error) {
// Execute GET on service.
resp, err := c.executeMethod(context.Background(), "GET", requestMetadata{contentSHA256Hex: emptySHA256Hex})

if err != nil {
closeResponse(resp)
return nil, err
}
if resp != nil {
if resp.StatusCode != http.StatusOK {
errResponse := ToErrorResponse(httpRespToErrorResponse(resp, "", ""))
closeResponse(resp)
if errResponse.Code != "AuthorizationHeaderMalformed" && errResponse.Code != "InvalidRegion" {
return nil, httpRespToErrorResponse(resp, "", "")
}
// Retry with the region returned by the server.
resp, err = c.executeMethod(context.Background(), "GET", requestMetadata{contentSHA256Hex: emptySHA256Hex, bucketLocation: errResponse.Region})
}
}

defer closeResponse(resp)
if err != nil {
return nil, err
Expand Down

0 comments on commit 1726b1f

Please sign in to comment.