Skip to content

Commit c77c52d

Browse files
committed
Fix redirect handler setup error
1 parent e90f19a commit c77c52d

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

httpclient/httpclient_client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ func BuildClient(config ClientConfig) (*Client, error) {
122122
}
123123

124124
// Conditionally setup redirect handling
125-
redirecthandler.SetupRedirectHandler(httpClient, config.ClientOptions.FollowRedirects, config.ClientOptions.MaxRedirects, log)
126-
125+
if err := redirecthandler.SetupRedirectHandler(httpClient, config.ClientOptions.FollowRedirects, config.ClientOptions.MaxRedirects, log); err != nil {
126+
log.Error("Failed to set up redirect handler", zap.Error(err))
127+
return nil, err
128+
}
127129
// Create a new HTTP client with the provided configuration.
128130
client := &Client{
129131
APIHandler: apiHandler,

redirecthandler/redirecthandler.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,16 @@ func (r *RedirectHandler) GetRedirectHistory(req *http.Request) []*url.URL {
217217
}
218218

219219
// SetupRedirectHandler configures the HTTP client for redirect handling based on the client configuration.
220-
func SetupRedirectHandler(client *http.Client, followRedirects bool, maxRedirects int, log logger.Logger) {
220+
func SetupRedirectHandler(client *http.Client, followRedirects bool, maxRedirects int, log logger.Logger) error {
221221
if followRedirects {
222+
if maxRedirects < 0 {
223+
log.Error("Invalid maxRedirects value", zap.Int("maxRedirects", maxRedirects))
224+
return fmt.Errorf("invalid maxRedirects value: %d", maxRedirects)
225+
}
226+
222227
redirectHandler := NewRedirectHandler(log, maxRedirects)
223228
redirectHandler.WithRedirectHandling(client)
224229
log.Info("Redirect handling enabled", zap.Int("MaxRedirects", maxRedirects))
225230
}
231+
return nil
226232
}

0 commit comments

Comments
 (0)