One of the problems I encountered early on is that the some of the web pages bookmarked would redirect to some other location. Simply checking for HTTP response code 200 was insufficient. I needed to check for redirection as well.
A quick Google search for "ruby follow http redirect" yields lots of results. Unfortunately, they're all very similar, and not quite right. In general, the examples you come across (even the one in the official Ruby documentation) don't handle the case when the redirected location is path relative to the original location. So you end up doing a get on a URL that looks like "../../redirected/location/index.html," which clearly won't work.
It turns out that detecting relative redirection is fairly straightforward:
until( found || attempts>=@@MAX_ATTEMPTS)
http.open_timeout = 10
http.read_timeout = 10
path="/" if path==""
if url.instance_of? URI::HTTPS
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
puts "url was relative"
found=true #resp was 404, etc
end #end if location
The trick here is to ask the redirected url object if it is relative. If it is, then add the redirected path onto the old url object. the URI class overrides the '+' operator (what is this, C++?) so that you can concatenate the new path onto the old URL, by doing: