Fixing follow-host-redirects option when customizing the host request header

This commit is contained in:
z0ne 2021-10-15 15:31:08 +08:00
parent 0a26550cd2
commit 9b53795521

View File

@ -75,7 +75,10 @@ func New(options *Options) (*HTTPX, error) {
redirectFunc = func(redirectedRequest *http.Request, previousRequests []*http.Request) error {
// Check if we get a redirect to a different host
var newHost = redirectedRequest.URL.Host
var oldHost = previousRequests[0].URL.Host
var oldHost = previousRequests[0].Host
if oldHost == "" {
oldHost = previousRequests[0].URL.Host
}
if newHost != oldHost {
// Tell the http client to not follow redirect
return http.ErrUseLastResponse