feross / simple-get

Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines
MIT License
401 stars 50 forks source link

How to figure out redirected URL? #45

Open billiegoose opened 5 years ago

billiegoose commented 5 years ago

Since POST doesn't follow redirects (per design, see #35), I need to be able to detect when a redirect happens and figure out the new URL, so I can re-issue my POST request.

Actually, git does a GET request before each POST request, so I can probably detect the redirect from the first GET request and infer the new correct path for the POST request before I make it. But either way, basically I need to recover the new URL after redirection is resolved.

Here's what I have so far:

get('https://github.com/wmhilton/isomorphic-git', (err, res) => console.log(res.req.path))

That gets me the path, but I haven't figured out the best way to get the protocol/hostname/port.