Skip to content

Commit e1c7a2c

Browse files
committed
Removed redirect, changed to a settable func. http client has a default setting anyway.
1 parent cf89944 commit e1c7a2c

File tree

3 files changed

+3
-17
lines changed

3 files changed

+3
-17
lines changed

httpclient/client.go

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

1515
"github.com/deploymenttheory/go-api-http-client/concurrency"
16-
"github.com/deploymenttheory/go-api-http-client/redirect"
1716
"go.uber.org/zap"
1817
)
1918

@@ -68,7 +67,7 @@ type ClientConfig struct {
6867

6968
// EnableCustomRedirectLogic allows the client to follow redirections when they're returned from a request.
7069
// Toggleable for debug reasons only
71-
EnableCustomRedirectLogic bool `json:"follow_redirects"`
70+
CustomRedirectPolicy *func(req *http.Request, via []*http.Request) error
7271

7372
// MaxRedirects is the maximum amount of redirects the client will follow before throwing an error.
7473
MaxRedirects int `json:"max_redirects"`
@@ -109,9 +108,8 @@ func (c *ClientConfig) Build() (*Client, error) {
109108
Timeout: c.CustomTimeout,
110109
}
111110

112-
// TODO refactor redirects
113-
if c.EnableCustomRedirectLogic {
114-
redirect.SetCustomRedirect(httpClient, c.MaxRedirects, c.Sugar)
111+
if c.CustomRedirectPolicy != nil {
112+
httpClient.CheckRedirect = *c.CustomRedirectPolicy
115113
}
116114

117115
// TODO refactor concurrency

httpclient/config_validation.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ const (
2626
DefaultCustomTimeout = 5 * time.Second
2727
DefaultTokenRefreshBufferPeriod = 2 * time.Minute
2828
DefaultTotalRetryDuration = 5 * time.Minute
29-
DefaultCustomRedirects = true
30-
DefaultMaxRedirects = 5
3129
DefaultEnableConcurrencyManagement = false
3230
)
3331

@@ -71,8 +69,6 @@ func LoadConfigFromEnv() (*ClientConfig, error) {
7169
CustomTimeout: getEnvAsDuration("CUSTOM_TIMEOUT", DefaultCustomTimeout),
7270
TokenRefreshBufferPeriod: getEnvAsDuration("TOKEN_REFRESH_BUFFER_PERIOD", DefaultTokenRefreshBufferPeriod),
7371
TotalRetryDuration: getEnvAsDuration("TOTAL_RETRY_DURATION", DefaultTotalRetryDuration),
74-
EnableCustomRedirectLogic: getEnvAsBool("CUSTOM_REDIRECTS", DefaultCustomRedirects),
75-
MaxRedirects: getEnvAsInt("MAX_REDIRECTS", DefaultMaxRedirects),
7672
EnableConcurrencyManagement: getEnvAsBool("ENABLE_CONCURRENCY_MANAGEMENT", DefaultEnableConcurrencyManagement),
7773
}
7874

@@ -134,12 +130,6 @@ func (c ClientConfig) validateClientConfig() error {
134130

135131
}
136132

137-
if c.EnableCustomRedirectLogic {
138-
if DefaultMaxRedirects < 1 {
139-
return errors.New("max redirects cannot be less than 1")
140-
}
141-
}
142-
143133
return nil
144134
}
145135

@@ -152,7 +142,5 @@ func (c *ClientConfig) SetDefaultValuesClientConfig() {
152142
setDefaultDuration(&c.CustomTimeout, DefaultCustomTimeout)
153143
setDefaultDuration(&c.TokenRefreshBufferPeriod, DefaultTokenRefreshBufferPeriod)
154144
setDefaultDuration(&c.TotalRetryDuration, DefaultTotalRetryDuration)
155-
setDefaultBool(&c.EnableCustomRedirectLogic, DefaultCustomRedirects)
156-
setDefaultInt(&c.MaxRedirects, DefaultMaxRedirects, 0)
157145
setDefaultBool(&c.EnableConcurrencyManagement, DefaultEnableConcurrencyManagement)
158146
}
File renamed without changes.

0 commit comments

Comments
 (0)