require 'net/http' # WARNING do not use this; it works but is very limited def resolve url res = Net::HTTP.get_response URI(url) if res.code == '301' then res['location'] else url.to_s end end # Why the above method sucks: # - doesn't handle multiple redirects # - uses HTTP GET instead of HEAD (slower, wasted bandwidth) # - no HTTP error and Ruby exception handling # - no HTTPS support # - no strict timeouts (lookups can block for too long)