Skip to content

Commit

Permalink
adjusted redirect key
Browse files Browse the repository at this point in the history
  • Loading branch information
thejoeker12 committed Jul 9, 2024
1 parent 666e22f commit cf89944
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions httpclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import (
"time"

"github.com/deploymenttheory/go-api-http-client/concurrency"
"github.com/deploymenttheory/go-api-http-client/redirect"
"go.uber.org/zap"

"github.com/deploymenttheory/go-api-http-client/redirecthandler"
)

const ()
Expand Down Expand Up @@ -67,8 +66,9 @@ type ClientConfig struct {
// TotalRetryDuration // TODO maybe this should be called context?
TotalRetryDuration time.Duration

// FollowRedirects allows the client to follow redirections when they're returned from a request.
FollowRedirects bool `json:"follow_redirects"`
// EnableCustomRedirectLogic allows the client to follow redirections when they're returned from a request.
// Toggleable for debug reasons only
EnableCustomRedirectLogic bool `json:"follow_redirects"`

// MaxRedirects is the maximum amount of redirects the client will follow before throwing an error.
MaxRedirects int `json:"max_redirects"`
Expand Down Expand Up @@ -110,8 +110,8 @@ func (c *ClientConfig) Build() (*Client, error) {
}

// TODO refactor redirects
if c.FollowRedirects {
redirecthandler.SetupRedirectHandler(httpClient, c.MaxRedirects, c.Sugar)
if c.EnableCustomRedirectLogic {
redirect.SetCustomRedirect(httpClient, c.MaxRedirects, c.Sugar)
}

// TODO refactor concurrency
Expand Down
8 changes: 4 additions & 4 deletions httpclient/config_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
DefaultCustomTimeout = 5 * time.Second
DefaultTokenRefreshBufferPeriod = 2 * time.Minute
DefaultTotalRetryDuration = 5 * time.Minute
DefaultFollowRedirects = false
DefaultCustomRedirects = true
DefaultMaxRedirects = 5
DefaultEnableConcurrencyManagement = false
)
Expand Down Expand Up @@ -71,7 +71,7 @@ func LoadConfigFromEnv() (*ClientConfig, error) {
CustomTimeout: getEnvAsDuration("CUSTOM_TIMEOUT", DefaultCustomTimeout),
TokenRefreshBufferPeriod: getEnvAsDuration("TOKEN_REFRESH_BUFFER_PERIOD", DefaultTokenRefreshBufferPeriod),
TotalRetryDuration: getEnvAsDuration("TOTAL_RETRY_DURATION", DefaultTotalRetryDuration),
FollowRedirects: getEnvAsBool("FOLLOW_REDIRECTS", DefaultFollowRedirects),
EnableCustomRedirectLogic: getEnvAsBool("CUSTOM_REDIRECTS", DefaultCustomRedirects),
MaxRedirects: getEnvAsInt("MAX_REDIRECTS", DefaultMaxRedirects),
EnableConcurrencyManagement: getEnvAsBool("ENABLE_CONCURRENCY_MANAGEMENT", DefaultEnableConcurrencyManagement),
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func (c ClientConfig) validateClientConfig() error {

}

if c.FollowRedirects {
if c.EnableCustomRedirectLogic {
if DefaultMaxRedirects < 1 {
return errors.New("max redirects cannot be less than 1")
}
Expand All @@ -152,7 +152,7 @@ func (c *ClientConfig) SetDefaultValuesClientConfig() {
setDefaultDuration(&c.CustomTimeout, DefaultCustomTimeout)
setDefaultDuration(&c.TokenRefreshBufferPeriod, DefaultTokenRefreshBufferPeriod)
setDefaultDuration(&c.TotalRetryDuration, DefaultTotalRetryDuration)
setDefaultBool(&c.FollowRedirects, DefaultFollowRedirects)
setDefaultBool(&c.EnableCustomRedirectLogic, DefaultCustomRedirects)
setDefaultInt(&c.MaxRedirects, DefaultMaxRedirects, 0)
setDefaultBool(&c.EnableConcurrencyManagement, DefaultEnableConcurrencyManagement)
}
4 changes: 2 additions & 2 deletions redirecthandler/redirecthandler.go → redirect/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package redirecthandler
package redirect

import (
"fmt"
Expand Down Expand Up @@ -222,7 +222,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, maxRedirects int, log *zap.SugaredLogger) {
func SetCustomRedirect(client *http.Client, maxRedirects int, log *zap.SugaredLogger) {
redirectHandler := NewRedirectHandler(log, maxRedirects)
redirectHandler.WithRedirectHandling(client)
log.Info("Redirect handling enabled", zap.Int("MaxRedirects", maxRedirects))
Expand Down

0 comments on commit cf89944

Please sign in to comment.