Skip to content

Commit cf89944

Browse files
committed
adjusted redirect key
1 parent 666e22f commit cf89944

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

httpclient/client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ import (
1313
"time"
1414

1515
"github.com/deploymenttheory/go-api-http-client/concurrency"
16+
"github.com/deploymenttheory/go-api-http-client/redirect"
1617
"go.uber.org/zap"
17-
18-
"github.com/deploymenttheory/go-api-http-client/redirecthandler"
1918
)
2019

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

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

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

112112
// TODO refactor redirects
113-
if c.FollowRedirects {
114-
redirecthandler.SetupRedirectHandler(httpClient, c.MaxRedirects, c.Sugar)
113+
if c.EnableCustomRedirectLogic {
114+
redirect.SetCustomRedirect(httpClient, c.MaxRedirects, c.Sugar)
115115
}
116116

117117
// TODO refactor concurrency

httpclient/config_validation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const (
2626
DefaultCustomTimeout = 5 * time.Second
2727
DefaultTokenRefreshBufferPeriod = 2 * time.Minute
2828
DefaultTotalRetryDuration = 5 * time.Minute
29-
DefaultFollowRedirects = false
29+
DefaultCustomRedirects = true
3030
DefaultMaxRedirects = 5
3131
DefaultEnableConcurrencyManagement = false
3232
)
@@ -71,7 +71,7 @@ func LoadConfigFromEnv() (*ClientConfig, error) {
7171
CustomTimeout: getEnvAsDuration("CUSTOM_TIMEOUT", DefaultCustomTimeout),
7272
TokenRefreshBufferPeriod: getEnvAsDuration("TOKEN_REFRESH_BUFFER_PERIOD", DefaultTokenRefreshBufferPeriod),
7373
TotalRetryDuration: getEnvAsDuration("TOTAL_RETRY_DURATION", DefaultTotalRetryDuration),
74-
FollowRedirects: getEnvAsBool("FOLLOW_REDIRECTS", DefaultFollowRedirects),
74+
EnableCustomRedirectLogic: getEnvAsBool("CUSTOM_REDIRECTS", DefaultCustomRedirects),
7575
MaxRedirects: getEnvAsInt("MAX_REDIRECTS", DefaultMaxRedirects),
7676
EnableConcurrencyManagement: getEnvAsBool("ENABLE_CONCURRENCY_MANAGEMENT", DefaultEnableConcurrencyManagement),
7777
}
@@ -134,7 +134,7 @@ func (c ClientConfig) validateClientConfig() error {
134134

135135
}
136136

137-
if c.FollowRedirects {
137+
if c.EnableCustomRedirectLogic {
138138
if DefaultMaxRedirects < 1 {
139139
return errors.New("max redirects cannot be less than 1")
140140
}
@@ -152,7 +152,7 @@ func (c *ClientConfig) SetDefaultValuesClientConfig() {
152152
setDefaultDuration(&c.CustomTimeout, DefaultCustomTimeout)
153153
setDefaultDuration(&c.TokenRefreshBufferPeriod, DefaultTokenRefreshBufferPeriod)
154154
setDefaultDuration(&c.TotalRetryDuration, DefaultTotalRetryDuration)
155-
setDefaultBool(&c.FollowRedirects, DefaultFollowRedirects)
155+
setDefaultBool(&c.EnableCustomRedirectLogic, DefaultCustomRedirects)
156156
setDefaultInt(&c.MaxRedirects, DefaultMaxRedirects, 0)
157157
setDefaultBool(&c.EnableConcurrencyManagement, DefaultEnableConcurrencyManagement)
158158
}

redirecthandler/redirecthandler.go renamed to redirect/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package redirecthandler
1+
package redirect
22

33
import (
44
"fmt"
@@ -222,7 +222,7 @@ func (r *RedirectHandler) GetRedirectHistory(req *http.Request) []*url.URL {
222222
}
223223

224224
// SetupRedirectHandler configures the HTTP client for redirect handling based on the client configuration.
225-
func SetupRedirectHandler(client *http.Client, maxRedirects int, log *zap.SugaredLogger) {
225+
func SetCustomRedirect(client *http.Client, maxRedirects int, log *zap.SugaredLogger) {
226226
redirectHandler := NewRedirectHandler(log, maxRedirects)
227227
redirectHandler.WithRedirectHandling(client)
228228
log.Info("Redirect handling enabled", zap.Int("MaxRedirects", maxRedirects))

0 commit comments

Comments
 (0)