Given a complete URL, I need to handle every possible kind of valid relative URL, like you might see in an HREF attribute on the page at the first location, or in a Location: header.
Examples:
Complete: http://example.com/foo/bar.html
Input: calico.gif
Result: http://example.com/foo/calico.gif
Complete: http://example.com/foo/bar.html
Input: ../x.html
Result: http://example.com/x.html
Complete: http://example.com/foo/bar.html
Input: /robots.txt
Result: http://example.com/robots.txt
Question
How can I reliably handle these sorts of relative URLs? I have to imagine someone has written solid code for this before.
and just call
.to_sto get a string.