Skip to content

Commit

Permalink
BKTCLT-18 fix + add idempotency support
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-gramain committed Sep 6, 2024
1 parent 641be8b commit 71cbc90
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions go-client/pkg/bucketclient/bucketclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func parseRequestOptions(opts ...any) (optionsSet, error) {
func (client *BucketClient) Request(apiMethod string, httpMethod string, resource string,
opts ...any) ([]byte, error) {
var response *http.Response
var err error

options, err := parseRequestOptions(opts...)
if err == nil {
Expand All @@ -64,11 +65,15 @@ func (client *BucketClient) Request(apiMethod string, httpMethod string, resourc
if options.requestBody != nil {
requestBodyReader = bytes.NewReader(options.requestBody)
}
request, err := http.NewRequest(httpMethod, url, requestBodyReader)
var request *http.Request
request, err = http.NewRequest(httpMethod, url, requestBodyReader)
if err == nil {
if options.requestBodyContentType != "" {
request.Header.Add("Content-Type", string(options.requestBodyContentType))
}
if options.idempotent {
request.Header["Idempotency-Key"] = []string{}
}
response, err = http.DefaultClient.Do(request)
}
}
Expand All @@ -77,7 +82,9 @@ func (client *BucketClient) Request(apiMethod string, httpMethod string, resourc
apiMethod, httpMethod, client.Endpoint, resource, 0, "", err,
}
}
defer response.Body.Close()
if response.Body != nil {
defer response.Body.Close()
}

if response.StatusCode / 100 != 2 {
splitStatus := strings.Split(response.Status, " ")
Expand Down

0 comments on commit 71cbc90

Please sign in to comment.