Skip to content

Commit

Permalink
Fixed Custom Redirect being used regardless if followRedirect is false
Browse files Browse the repository at this point in the history
In net/http, when defining a redirect function whether to follow or disable  redirects, you must always define a custom function in the transport. Using the custom redirect func in the clientConfig, it causes the .SetFollowRedirect() function to never work if provided with "false". By adding a check to ensure that follow redirects is enabled when updating the underlying client's transport, it allows you to enable and disable redirects per request, while also maintaining the custom redirect function when re-enabling follow redirects.
  • Loading branch information
MoneyKiddMo authored and bogdanfinn committed Aug 6, 2023
1 parent 7512bd3 commit a5ea8cb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (c *httpClient) applyFollowRedirect() {
c.CheckRedirect = defaultRedirectFunc
}

if c.config.customRedirectFunc != nil {
if c.config.customRedirectFunc != nil && c.config.followRedirects {
c.CheckRedirect = c.config.customRedirectFunc
}
}
Expand Down

0 comments on commit a5ea8cb

Please sign in to comment.