diff --git a/httpclient/client.go b/httpclient/client.go index ebf49cd..3e23d65 100644 --- a/httpclient/client.go +++ b/httpclient/client.go @@ -10,7 +10,6 @@ package httpclient import ( "fmt" "net/http" - "sync" "time" "github.com/deploymenttheory/go-api-http-client/concurrency" @@ -26,7 +25,6 @@ import ( type Client struct { config ClientConfig http *http.Client - lock sync.Mutex AuthToken string AuthTokenExpiry time.Time @@ -37,12 +35,9 @@ type Client struct { // Options/Variables for Client type ClientConfig struct { - Integration APIIntegration - HideSensitiveData bool - - // CookieJarEnabled bool - CustomCookies []*http.Cookie - + Integration APIIntegration + HideSensitiveData bool + CustomCookies []*http.Cookie MaxRetryAttempts int MaxConcurrentRequests int EnableDynamicRateLimiting bool @@ -61,16 +56,12 @@ func BuildClient(config ClientConfig, populateDefaultValues bool, log logger.Log return nil, fmt.Errorf("invalid configuration: %v", err) } - // TODO refactor logging. It makes files even when told not to! - log.Info(fmt.Sprintf("initializing new http client, auth: %s", config.Integration.Domain())) httpClient := &http.Client{ Timeout: config.CustomTimeout, } - // TODO Add Cookie Support - // TODO refactor redirects if err := redirecthandler.SetupRedirectHandler(httpClient, config.FollowRedirects, config.MaxRedirects, log); err != nil { log.Error("Failed to set up redirect handler", zap.Error(err)) @@ -98,7 +89,7 @@ func BuildClient(config ClientConfig, populateDefaultValues bool, log logger.Log } if len(client.config.CustomCookies) > 0 { - client.parseCustomCookies(config.CustomCookies) + client.loadCustomCookies(config.CustomCookies) } log.Debug("New API client initialized", diff --git a/httpclient/config.go b/httpclient/config_validation.go similarity index 100% rename from httpclient/config.go rename to httpclient/config_validation.go diff --git a/httpclient/cookies.go b/httpclient/cookies.go index ec0481e..ff9c5e2 100644 --- a/httpclient/cookies.go +++ b/httpclient/cookies.go @@ -7,11 +7,12 @@ import ( "net/url" ) -func (c *Client) parseCustomCookies(cookiesList []*http.Cookie) error { +func (c *Client) loadCustomCookies(cookiesList []*http.Cookie) error { cookieJar, err := cookiejar.New(nil) if err != nil { return err } + cookieUrl, err := url.Parse((*c.Integration).Domain()) if err != nil { @@ -20,7 +21,6 @@ func (c *Client) parseCustomCookies(cookiesList []*http.Cookie) error { c.http.Jar = cookieJar c.http.Jar.SetCookies(cookieUrl, cookiesList) - c.Logger.Debug(fmt.Sprintf("%+v", c.http.Jar)) return nil diff --git a/httpclient/integration.go b/httpclient/integration.go index e3abdb5..cb5c248 100644 --- a/httpclient/integration.go +++ b/httpclient/integration.go @@ -7,11 +7,8 @@ import ( // TODO comment type APIIntegration interface { - // Info Domain() string GetAuthMethodDescriptor() string - - // Utilities CheckRefreshToken() error PrepRequestParamsAndAuth(req *http.Request) error PrepRequestBody(body interface{}, method string, endpoint string) ([]byte, error) diff --git a/httpclient/utility.go b/httpclient/utility.go index d8dfbac..9abf70f 100644 --- a/httpclient/utility.go +++ b/httpclient/utility.go @@ -42,7 +42,7 @@ func validateValidClientID(clientID string) error { func validateClientSecret(clientSecret string) error { if len(clientSecret) < 16 { - return errors.New("client secret must be at least 16 characters long.") + return errors.New("client secret must be at least 16 characters long") } if matched, _ := regexp.MatchString(`[a-z]`, clientSecret); !matched { diff --git a/redirecthandler/redirecthandler.go b/redirecthandler/redirecthandler.go index 4daf0e3..8dd96fa 100644 --- a/redirecthandler/redirecthandler.go +++ b/redirecthandler/redirecthandler.go @@ -221,7 +221,7 @@ func (r *RedirectHandler) GetRedirectHistory(req *http.Request) []*url.URL { // SetupRedirectHandler configures the HTTP client for redirect handling based on the client configuration. func SetupRedirectHandler(client *http.Client, followRedirects bool, maxRedirects int, log logger.Logger) error { if followRedirects { - if maxRedirects < 0 { + if maxRedirects < 1 { log.Error("Invalid maxRedirects value", zap.Int("maxRedirects", maxRedirects)) return fmt.Errorf("invalid maxRedirects value: %d", maxRedirects) }