Skip to content

Commit

Permalink
retry makebucket on AuthorizationHeaderMalformed code and empty locat…
Browse files Browse the repository at this point in the history
…ion (minio#1292)

If makebucket was called with location not set and the server returns
AuthorizationHeaderMalformed with the correct region, use that and retry
makebucket again.
  • Loading branch information
kannappanr authored May 26, 2020
1 parent 44a5f2e commit 360c4f1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions api-put-bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,28 @@ type ServerSideEncryptionConfiguration struct {
/// Bucket operations

func (c Client) makeBucket(ctx context.Context, bucketName string, location string, objectLockEnabled bool) (err error) {
// Validate the input arguments.
if err := s3utils.CheckValidBucketNameStrict(bucketName); err != nil {
return err
}

err = c.doMakeBucket(ctx, bucketName, location, objectLockEnabled)
if err != nil && (location == "" || location == "us-east-1") {
if resp, ok := err.(ErrorResponse); ok && resp.Code == "AuthorizationHeaderMalformed" && resp.Region != "" {
err = c.doMakeBucket(ctx, bucketName, resp.Region, objectLockEnabled)
}
}
return err
}

func (c Client) doMakeBucket(ctx context.Context, bucketName string, location string, objectLockEnabled bool) (err error) {
defer func() {
// Save the location into cache on a successful makeBucket response.
if err == nil {
c.bucketLocCache.Set(bucketName, location)
}
}()

// Validate the input arguments.
if err := s3utils.CheckValidBucketNameStrict(bucketName); err != nil {
return err
}

// If location is empty, treat is a default region 'us-east-1'.
if location == "" {
location = "us-east-1"
Expand Down

0 comments on commit 360c4f1

Please sign in to comment.