processes the getBucketLocation http response from the server.
(resp *http.Response, bucketName string)
| 76 | |
| 77 | // processes the getBucketLocation http response from the server. |
| 78 | func processBucketLocationResponse(resp *http.Response, bucketName string) (bucketLocation string, err error) { |
| 79 | if resp != nil { |
| 80 | if resp.StatusCode != http.StatusOK { |
| 81 | err = httpRespToErrorResponse(resp, bucketName, "") |
| 82 | errResp := ToErrorResponse(err) |
| 83 | // For access denied error, it could be an anonymous |
| 84 | // request. Move forward and let the top level callers |
| 85 | // succeed if possible based on their policy. |
| 86 | switch errResp.Code { |
| 87 | case NotImplemented: |
| 88 | switch errResp.Server { |
| 89 | case "AmazonSnowball": |
| 90 | return "snowball", nil |
| 91 | case "cloudflare": |
| 92 | return "us-east-1", nil |
| 93 | } |
| 94 | case AuthorizationHeaderMalformed: |
| 95 | fallthrough |
| 96 | case InvalidRegion: |
| 97 | fallthrough |
| 98 | case AccessDenied: |
| 99 | if errResp.Region == "" { |
| 100 | return "us-east-1", nil |
| 101 | } |
| 102 | return errResp.Region, nil |
| 103 | } |
| 104 | return "", err |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // Extract location. |
| 109 | var locationConstraint string |
| 110 | err = xmlDecoder(resp.Body, &locationConstraint) |
| 111 | if err != nil { |
| 112 | return "", err |
| 113 | } |
| 114 | |
| 115 | location := locationConstraint |
| 116 | // Location is empty will be 'us-east-1'. |
| 117 | if location == "" { |
| 118 | location = "us-east-1" |
| 119 | } |
| 120 | |
| 121 | // Location can be 'EU' convert it to meaningful 'eu-west-1'. |
| 122 | if location == "EU" { |
| 123 | location = "eu-west-1" |
| 124 | } |
| 125 | |
| 126 | // Save the location into cache. |
| 127 | |
| 128 | // Return. |
| 129 | return location, nil |
| 130 | } |
| 131 | |
| 132 | // getBucketLocationRequest - Wrapper creates a new getBucketLocation request. |
| 133 | func (c *Client) getBucketLocationRequest(ctx context.Context, bucketName string) (*http.Request, error) { |