Getting final URL during HTTP redirection

I need URL resolution for some software I’m working on. Better put, I
want to figure out the final URL at which you land when requesting some
initial URL. I have no interest in the page data itself.

Properly handling redirects robustly is difficult due to the horrific
tendency of many developers and servers to improperly handle them. You’d
expect a Location header, but I’ve run into several other possible
responses ranging from Redirect headers to html meta tags.

Is there some library out there that will make my job easier, or will I
have to roll my own. Keep in mind I want the URL that was last
requested, not the response from that request.

Thanks!

What makes this problem even more difficult is that redirects could
happen on the client side. It’s something that I’ve been looking into
a lot lately, but no luck yet. I’d be very interested if anybody knows
of a good solution that could handle this as well.

Michael