Redir refactor

As @vmg mentioned in [that other PR](https://github.com/libgit2/libgit2/pull/1877/files#r6584873), there was a lot of duplication when the HTTP->HTTPS redirect problem got fixed. This PR pulls out the common code to a central utility, and replaces the copypasta.