Gating the HTTP/HTTPS redirect with a followCrossRedirects flag

As a security measure, adding a flag to enable cross HTTP/HTTPS redirects. The code has also been rearranged a bit to make it more readable.