getBucketLocationRequest - Wrapper creates a new getBucketLocation request.
(ctx context.Context, bucketName string)
| 131 | |
| 132 | // getBucketLocationRequest - Wrapper creates a new getBucketLocation request. |
| 133 | func (c *Client) getBucketLocationRequest(ctx context.Context, bucketName string) (*http.Request, error) { |
| 134 | // Set location query. |
| 135 | urlValues := make(url.Values) |
| 136 | urlValues.Set("location", "") |
| 137 | |
| 138 | // Set get bucket location always as path style. |
| 139 | targetURL := *c.endpointURL |
| 140 | |
| 141 | // as it works in makeTargetURL method from api.go file |
| 142 | if h, p, err := net.SplitHostPort(targetURL.Host); err == nil { |
| 143 | if targetURL.Scheme == "http" && p == "80" || targetURL.Scheme == "https" && p == "443" { |
| 144 | targetURL.Host = h |
| 145 | if ip := net.ParseIP(h); ip != nil && ip.To4() == nil { |
| 146 | targetURL.Host = "[" + h + "]" |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | isVirtualStyle := c.isVirtualHostStyleRequest(targetURL, bucketName) |
| 152 | |
| 153 | var urlStr string |
| 154 | |
| 155 | if isVirtualStyle { |
| 156 | urlStr = c.endpointURL.Scheme + "://" + bucketName + "." + targetURL.Host + "/?location" |
| 157 | } else { |
| 158 | targetURL.Path = path.Join(bucketName, "") + "/" |
| 159 | targetURL.RawQuery = urlValues.Encode() |
| 160 | urlStr = targetURL.String() |
| 161 | } |
| 162 | |
| 163 | // Get a new HTTP request for the method. |
| 164 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, urlStr, nil) |
| 165 | if err != nil { |
| 166 | return nil, err |
| 167 | } |
| 168 | |
| 169 | // Set UserAgent for the request. |
| 170 | c.setUserAgent(req) |
| 171 | |
| 172 | // Get credentials from the configured credentials provider. |
| 173 | value, err := c.credsProvider.GetWithContext(c.CredContext()) |
| 174 | if err != nil { |
| 175 | return nil, err |
| 176 | } |
| 177 | |
| 178 | var ( |
| 179 | signerType = value.SignerType |
| 180 | accessKeyID = value.AccessKeyID |
| 181 | secretAccessKey = value.SecretAccessKey |
| 182 | sessionToken = value.SessionToken |
| 183 | ) |
| 184 | |
| 185 | // Custom signer set then override the behavior. |
| 186 | if c.overrideSignerType != credentials.SignatureDefault { |
| 187 | signerType = c.overrideSignerType |
| 188 | } |
| 189 | |
| 190 | // If signerType returned by credentials helper is anonymous, |