Skip to content

Commit

Permalink
Introduce DisableRedirectPathNormalizing field to Request
Browse files Browse the repository at this point in the history
  • Loading branch information
skidder committed Oct 26, 2023
1 parent fea99c3 commit b30207a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ func doRequestFollowRedirects(req *Request, resp *Response, url string, maxRedir
err = ErrMissingLocation
break
}
url = getRedirectURL(url, location, req.uri.DisablePathNormalizing)
url = getRedirectURL(url, location, req.DisableRedirectPathNormalizing)
}

return statusCode, body, err
Expand Down
1 change: 1 addition & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,7 @@ func TestClientFollowRedirects(t *testing.T) {

req.SetRequestURI("http://xxx/abc/*/123")
req.URI().DisablePathNormalizing = true
req.DisableRedirectPathNormalizing = true

err := c.DoRedirects(req, resp, 16)
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ type Request struct {

// Use Host header (request.Header.SetHost) instead of the host from SetRequestURI, SetHost, or URI().SetHost
UseHostHeader bool

// Redirect path values are sent as-is without normalization
//
// Disabled redirect path normalization may be useful for proxying incoming requests
// to servers that are expecting paths to be forwarded as-is.
//
// By default redirect path values are normalized, i.e.
// extra slashes are removed, special characters are encoded.
DisableRedirectPathNormalizing bool
}

// Response represents HTTP response.
Expand Down Expand Up @@ -1080,6 +1089,7 @@ func (req *Request) Reset() {
req.resetSkipHeader()
req.timeout = 0
req.UseHostHeader = false
req.DisableRedirectPathNormalizing = false
}

func (req *Request) resetSkipHeader() {
Expand Down

0 comments on commit b30207a

Please sign in to comment.