I made a handy little link expander using curl within my ruby (Sintra) app.
def curbexpand(link)
result = Curl::Easy.new(link)
begin
result.headers["User-Agent"] = "..."
result.verbose = true
result.follow_location = true
result.max_redirects = 3
result.connect_timeout = 5
result.perform
return result.last_effective_url # Returns the final destination URL after x redirects...
rescue
return link
puts "XXXXXXXXXXXXXXXXXXX Error parsing link XXXXXXXXXXXXXXXXXXXXXXXXXXX"
end
end
The problem I have is that some geniuses are using URL shorteners to link to .exe's and .dmg's which would be fine but it looks like my curl script above is waiting for the full response to be returned (i.e. it could be a 1GB file!) before returning the url. I don't want to use third party link expander API's as I have a significant volume of links to expand.
Anyone know how I can tweak curb to just find the url rather than waiting for the full response?