Hi,
http.Get follows HTTP redirects. I don't want to follow the redirect, but want to check the redirect URL.
How do I do this? There is a http.client.checkRedirect function, that should be tweaked when customising this behaviour. But how do I check the redirect URL inside it?
I have something like:
var client = &http.Client{}
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
return errors.New("redirects to " + req.URL.String())
}
var url = "
http://localhost"
var newurl = "
https://localhost"
req, err = http.Get(url, nil)
This fails on every redirect. I would like to check if req.URL matches the newurl. But how? I pass no this parameter to CheckRedirect, so this variable is not accessible in that scope.
Is that possible in some easy way?