Skip to content

Commit 3f0ac05

Browse files
committed
Add executeRequest method to HttpClient
1 parent 81fe8d9 commit 3f0ac05

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

httpclient/httpclient_request.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@ import (
1313
"go.uber.org/zap"
1414
)
1515

16+
func (c *Client) executeRequest(req *http.Request, log logger.Logger) (*http.Response, error) {
17+
// Start response time measurement
18+
responseTimeStart := time.Now()
19+
20+
// Execute the request
21+
resp, err := c.httpClient.Do(req)
22+
if err != nil {
23+
log.Error("Failed to send request", zap.String("method", req.Method), zap.String("url", req.URL.String()), zap.Error(err))
24+
return nil, err
25+
}
26+
27+
// Compute and update response time
28+
responseDuration := time.Since(responseTimeStart)
29+
c.PerfMetrics.lock.Lock()
30+
c.PerfMetrics.TotalResponseTime += responseDuration
31+
c.PerfMetrics.lock.Unlock()
32+
33+
// Check for the presence of a deprecation header in the HTTP response and log if found
34+
CheckDeprecationHeader(resp, log)
35+
36+
// Basic response status check
37+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
38+
log.Warn("Received non-success HTTP status", zap.String("method", req.Method), zap.String("url", req.URL.String()), zap.Int("status_code", resp.StatusCode))
39+
}
40+
41+
return resp, nil
42+
}
43+
1644
// DoRequest constructs and executes a standard HTTP request with support for retry logic.
1745
// It is intended for operations that can be encoded in a single JSON or XML body such as
1846
// creating or updating resources. This method includes token validation, concurrency control,

0 commit comments

Comments
 (0)