Skip to content

Commit 1c671d4

Browse files
authored
Merge pull request #257 from deploymenttheory/dev-jl
More tidyup operations
2 parents b9ca2b0 + 2cddca6 commit 1c671d4

File tree

4 files changed

+6
-21
lines changed

4 files changed

+6
-21
lines changed

httpclient/methods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import "net/http"
2020
*/
2121

2222
// IsIdempotentHTTPMethod checks if the given HTTP method is idempotent.
23-
func IsIdempotentHTTPMethod(method string) bool {
23+
func isIdempotentHTTPMethod(method string) bool {
2424
methodsMap := map[string]bool{
2525
http.MethodGet: true,
2626
http.MethodPut: true,

httpclient/multipartrequest.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ func (c *Client) DoMultiPartRequest(method, endpoint string, files map[string][]
112112
return nil, err
113113
}
114114

115-
// sugar the request details
116115
c.Sugar.Info("Created HTTP Multipart request", zap.String("method", method), zap.String("url", url), zap.String("content_type", contentType))
117116

118117
(*c.Integration).PrepRequestParamsAndAuth(req)

httpclient/request.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,15 @@ import (
5959
// - The decision to retry requests is based on the idempotency of the HTTP method and the client's retry configuration,
6060
// including maximum retry attempts and total retry duration.
6161
func (c *Client) DoRequest(method, endpoint string, body, out interface{}) (*http.Response, error) {
62-
if !c.config.RetryEligiableRequests {
63-
return c.requestNoRetries(method, endpoint, body, out)
64-
}
6562

66-
if IsIdempotentHTTPMethod(method) {
67-
return c.requestWithRetries(method, endpoint, body, out)
68-
} else if !IsIdempotentHTTPMethod(method) {
63+
if !c.config.RetryEligiableRequests || !isIdempotentHTTPMethod(method) {
6964
return c.requestNoRetries(method, endpoint, body, out)
7065
}
7166

72-
return nil, fmt.Errorf("unsupported http method: %s", method)
67+
return c.requestWithRetries(method, endpoint, body, out)
7368
}
7469

75-
// region comment
76-
// executeRequestWithRetries executes an HTTP request using the specified method, endpoint, request body, and output variable.
70+
// requestWithRetries executes an HTTP request using the specified method, endpoint, request body, and output variable.
7771
// It is designed for idempotent HTTP methods (GET, PUT, DELETE), where the request can be safely retried in case of
7872
// transient errors or rate limiting. The function implements a retry mechanism that respects the client's configuration
7973
// for maximum retry attempts and total retry duration. Each retry attempt uses exponential backoff with jitter to avoid
@@ -102,7 +96,6 @@ func (c *Client) DoRequest(method, endpoint string, body, out interface{}) (*htt
10296
// - The function respects the client's concurrency token, acquiring and releasing it as needed to ensure safe concurrent
10397
// operations.
10498
// - The retry mechanism employs exponential backoff with jitter to mitigate the impact of retries on the server.
105-
// endregion
10699
func (c *Client) requestWithRetries(method, endpoint string, body, out interface{}) (*http.Response, error) {
107100
var resp *http.Response
108101
var err error
@@ -188,7 +181,7 @@ func (c *Client) requestWithRetries(method, endpoint string, body, out interface
188181
return resp, response.HandleAPIErrorResponse(resp, c.Sugar)
189182
}
190183

191-
// executeRequest executes an HTTP request using the specified method, endpoint, and request body without implementing
184+
// requestNoRetries executes an HTTP request using the specified method, endpoint, and request body without implementing
192185
// retry logic. It is primarily designed for non-idempotent HTTP methods like POST and PATCH, where the request should
193186
// not be automatically retried within this function due to the potential side effects of re-submitting the same data.
194187
// Parameters:
@@ -225,11 +218,9 @@ func (c *Client) requestNoRetries(method, endpoint string, body, out interface{}
225218
return nil, err
226219
}
227220

228-
c.Sugar.Debug("LOGHERE")
229221
c.Sugar.Debugf("Status Code: %v", resp.StatusCode)
230222

231223
if resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusBadRequest {
232-
c.Sugar.Debug("FLAG 1 - Request Considered Successful")
233224
if resp.StatusCode == http.StatusPermanentRedirect || resp.StatusCode == http.StatusTemporaryRedirect {
234225
c.Sugar.Warn("Redirect response received", zap.Int("status_code", resp.StatusCode), zap.String("location", resp.Header.Get("Location")))
235226
}
@@ -238,15 +229,12 @@ func (c *Client) requestNoRetries(method, endpoint string, body, out interface{}
238229
return resp, response.HandleAPISuccessResponse(resp, out, c.Sugar)
239230
}
240231

241-
c.Sugar.Debug("FLAG 2 - Request Considered NOT Successful")
242-
243232
return nil, response.HandleAPIErrorResponse(resp, c.Sugar)
244233
}
245234

246-
// TODO function comment
235+
// request is a base leve private function which the contextual functions above utilise to make requests // TODO improve this comment probably.
247236
func (c *Client) request(ctx context.Context, method, endpoint string, body interface{}) (*http.Response, error) {
248237

249-
// TODO Concurrency - Refactor or remove this
250238
if c.config.EnableConcurrencyManagement {
251239
_, requestID, err := c.Concurrency.AcquireConcurrencyPermit(ctx)
252240
if err != nil {

httpclient/utility.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ func validatePassword(password string) error {
8484
return nil
8585
}
8686

87-
// environment variable mapping helpers
88-
8987
// getEnvAsString reads an environment variable as a string, with a fallback default value.
9088
func getEnvAsString(name string, defaultVal string) string {
9189
if value, exists := os.LookupEnv(name); exists {

0 commit comments

Comments
 (0)