Skip to content

Commit 2e10e1a

Browse files
authored
Merge pull request #242 from deploymenttheory/dev-jl-version2
small tidies
2 parents b2ea5b4 + a45474d commit 2e10e1a

File tree

6 files changed

+8
-20
lines changed

6 files changed

+8
-20
lines changed

httpclient/client.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ package httpclient
1010
import (
1111
"fmt"
1212
"net/http"
13-
"sync"
1413
"time"
1514

1615
"github.com/deploymenttheory/go-api-http-client/concurrency"
@@ -26,7 +25,6 @@ import (
2625
type Client struct {
2726
config ClientConfig
2827
http *http.Client
29-
lock sync.Mutex
3028

3129
AuthToken string
3230
AuthTokenExpiry time.Time
@@ -37,12 +35,9 @@ type Client struct {
3735

3836
// Options/Variables for Client
3937
type ClientConfig struct {
40-
Integration APIIntegration
41-
HideSensitiveData bool
42-
43-
// CookieJarEnabled bool
44-
CustomCookies []*http.Cookie
45-
38+
Integration APIIntegration
39+
HideSensitiveData bool
40+
CustomCookies []*http.Cookie
4641
MaxRetryAttempts int
4742
MaxConcurrentRequests int
4843
EnableDynamicRateLimiting bool
@@ -61,16 +56,12 @@ func BuildClient(config ClientConfig, populateDefaultValues bool, log logger.Log
6156
return nil, fmt.Errorf("invalid configuration: %v", err)
6257
}
6358

64-
// TODO refactor logging. It makes files even when told not to!
65-
6659
log.Info(fmt.Sprintf("initializing new http client, auth: %s", config.Integration.Domain()))
6760

6861
httpClient := &http.Client{
6962
Timeout: config.CustomTimeout,
7063
}
7164

72-
// TODO Add Cookie Support
73-
7465
// TODO refactor redirects
7566
if err := redirecthandler.SetupRedirectHandler(httpClient, config.FollowRedirects, config.MaxRedirects, log); err != nil {
7667
log.Error("Failed to set up redirect handler", zap.Error(err))
@@ -98,7 +89,7 @@ func BuildClient(config ClientConfig, populateDefaultValues bool, log logger.Log
9889
}
9990

10091
if len(client.config.CustomCookies) > 0 {
101-
client.parseCustomCookies(config.CustomCookies)
92+
client.loadCustomCookies(config.CustomCookies)
10293
}
10394

10495
log.Debug("New API client initialized",

httpclient/cookies.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"net/url"
88
)
99

10-
func (c *Client) parseCustomCookies(cookiesList []*http.Cookie) error {
10+
func (c *Client) loadCustomCookies(cookiesList []*http.Cookie) error {
1111
cookieJar, err := cookiejar.New(nil)
1212
if err != nil {
1313
return err
1414
}
15+
1516
cookieUrl, err := url.Parse((*c.Integration).Domain())
1617

1718
if err != nil {
@@ -20,7 +21,6 @@ func (c *Client) parseCustomCookies(cookiesList []*http.Cookie) error {
2021

2122
c.http.Jar = cookieJar
2223
c.http.Jar.SetCookies(cookieUrl, cookiesList)
23-
2424
c.Logger.Debug(fmt.Sprintf("%+v", c.http.Jar))
2525

2626
return nil

httpclient/integration.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ import (
77

88
// TODO comment
99
type APIIntegration interface {
10-
// Info
1110
Domain() string
1211
GetAuthMethodDescriptor() string
13-
14-
// Utilities
1512
CheckRefreshToken() error
1613
PrepRequestParamsAndAuth(req *http.Request) error
1714
PrepRequestBody(body interface{}, method string, endpoint string) ([]byte, error)

httpclient/utility.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func validateValidClientID(clientID string) error {
4242

4343
func validateClientSecret(clientSecret string) error {
4444
if len(clientSecret) < 16 {
45-
return errors.New("client secret must be at least 16 characters long.")
45+
return errors.New("client secret must be at least 16 characters long")
4646
}
4747

4848
if matched, _ := regexp.MatchString(`[a-z]`, clientSecret); !matched {

redirecthandler/redirecthandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func (r *RedirectHandler) GetRedirectHistory(req *http.Request) []*url.URL {
221221
// SetupRedirectHandler configures the HTTP client for redirect handling based on the client configuration.
222222
func SetupRedirectHandler(client *http.Client, followRedirects bool, maxRedirects int, log logger.Logger) error {
223223
if followRedirects {
224-
if maxRedirects < 0 {
224+
if maxRedirects < 1 {
225225
log.Error("Invalid maxRedirects value", zap.Int("maxRedirects", maxRedirects))
226226
return fmt.Errorf("invalid maxRedirects value: %d", maxRedirects)
227227
}

0 commit comments

Comments
 (0)