I am trying to find a method for entering a string of URIs / URLs from a user and determining the working, canonical form (or crashing if the resource is not valid). You should also check at the same time if the URL exists. Therefore, we check both the actual "syntax" and the existence.
For example, a string like google.com should be converted to http://www.google.com , and a string like google.com/insights should be converted to http://www.google.com/insights . A string like http://thiswebsitedoesntexistatall.com should return some error or exception.
I believe that part of the solution will most likely call the HTTP get_response() method after the redirect, until I get the 200 OK status.
It seems that the URI.parse() method does not forgive the rejection of http . I understand that I can write a simple thing to try to add http in front, etc., but I was hoping there was some existing jewel or little-known library function that would really forgive URLs and canonize them for me.
Both the built-in net/http and HTTParty seem too strict for what I'm looking for. Is there a good way to do this?
source share