ruby-on-railscurltyphoeus

Typhoeus: How to get the last redirected location?


How do I get the last redirected URL using Typhoeus? For instance, if I go to a Bit.ly URL, how do I get the "real" url it points to when making a request? I tried accessing response.headers_hash['Location'], but it seems to be nil for every request I am making, so I assume this is not how I should get the final location.

request = Typhoeus::Request.new(url, :timeout  => 3000, :followlocation => true)    

request.on_complete do |response|
    if response.success?
        location = response.headers_hash['Location'] #not working
        end
end

Solution

  • Just discovered the this gives you the final location of the redirect:

    lastUrl = response.effective_url