Skip to content

Commit

Permalink
use http.ErrUseLastResponse to prevent return error in NoRedirectPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
imroc committed Aug 10, 2022
1 parent 0cb6666 commit 19d3d87
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,7 @@ func TestKeepAlives(t *testing.T) {

func TestRedirect(t *testing.T) {
_, err := tc().SetRedirectPolicy(NoRedirectPolicy()).R().Get("/unlimited-redirect")
tests.AssertNotNil(t, err)
tests.AssertContains(t, err.Error(), "redirect is disabled", true)
tests.AssertIsNil(t, err)

_, err = tc().SetRedirectPolicy(MaxRedirectPolicy(3)).R().Get("/unlimited-redirect")
tests.AssertNotNil(t, err)
Expand Down
5 changes: 3 additions & 2 deletions redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func MaxRedirectPolicy(noOfRedirect int) RedirectPolicy {
// NoRedirectPolicy disable redirect behaviour
func NoRedirectPolicy() RedirectPolicy {
return func(req *http.Request, via []*http.Request) error {
return errors.New("redirect is disabled")
return http.ErrUseLastResponse
}
}

Expand Down Expand Up @@ -111,7 +111,8 @@ func getDomain(host string) string {
// sensitive ones to the same origin, or subdomains thereof (https://go-review.googlesource.com/c/go/+/28930/)
// Check discussion: https://github.com/golang/go/issues/4800
// For example:
// client.SetRedirectPolicy(req.AlwaysCopyHeaderRedirectPolicy("Authorization"))
//
// client.SetRedirectPolicy(req.AlwaysCopyHeaderRedirectPolicy("Authorization"))
func AlwaysCopyHeaderRedirectPolicy(headers ...string) RedirectPolicy {
return func(req *http.Request, via []*http.Request) error {
for _, header := range headers {
Expand Down

0 comments on commit 19d3d87

Please sign in to comment.