Skip to content

Commit

Permalink
Simplify redirect check (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
averche committed Jul 31, 2023
1 parent 7efc077 commit bbcc6be
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
11 changes: 4 additions & 7 deletions client_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"strings"

"github.com/hashicorp/go-retryablehttp"

"golang.org/x/exp/slices"
)

// Read attempts to read the value stored at the given Vault path.
Expand Down Expand Up @@ -371,13 +369,12 @@ func (c *Client) do(req *http.Request, retry bool) (*http.Response, error) {
// handleRedirect checks the given response for a redirect status & modifies
// the request accordingly if the redirect is needed
func (c *Client) handleRedirect(req *http.Request, resp *http.Response, redirectCount *int) (bool, *RedirectError) {
redirectStatuses := [...]int{
switch resp.StatusCode {
case
http.StatusMovedPermanently, // 301
http.StatusFound, // 302
http.StatusTemporaryRedirect, // 307
}

if !slices.Contains(redirectStatuses[:], resp.StatusCode) {
http.StatusTemporaryRedirect: // 307
default:
return false, nil
}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/hashicorp/go-rootcerts v1.0.2
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2
github.com/stretchr/testify v1.8.0
golang.org/x/exp v0.0.0-20220921164117-439092de6870
golang.org/x/sys v0.4.0
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
golang.org/x/exp v0.0.0-20220921164117-439092de6870 h1:j8b6j9gzSigH28O5SjSpQSSh9lFd6f5D/q0aHjNTulc=
golang.org/x/exp v0.0.0-20220921164117-439092de6870/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af h1:Yx9k8YCG3dvF87UAn2tu2HQLf2dt/eR1bXxpLMWeH+Y=
Expand Down

0 comments on commit bbcc6be

Please sign in to comment.