Skip to content

Commit

Permalink
fix: match max redirects with total requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rogercoll committed Sep 22, 2024
1 parent aef83ac commit c98fe0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 1 addition & 5 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,10 @@ func (hcs *ClientConfig) ToClient(ctx context.Context, host component.Host, sett
func makeCheckRedirect(max *int) func(*http.Request, []*http.Request) error {
if max == nil {
return nil
} else if *max == 0 {
return func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
}
}

return func(_ *http.Request, via []*http.Request) error {
if *max == len(via) {
if *max == (len(via) - 1) {
return http.ErrUseLastResponse
}
return nil
Expand Down
7 changes: 6 additions & 1 deletion config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,15 @@ func TestMaxRedirects(t *testing.T) {
settings: ClientConfig{MaxRedirects: toIntPtr(0)},
expectedRequests: 1,
},
{
name: "One redirect",
settings: ClientConfig{MaxRedirects: toIntPtr(1)},
expectedRequests: 2,
},
{
name: "Defined max redirects",
settings: ClientConfig{MaxRedirects: toIntPtr(5)},
expectedRequests: 5,
expectedRequests: 6,
},
}

Expand Down

0 comments on commit c98fe0a

Please sign in to comment.