Skip to content

Commit

Permalink
Updated to follow relative redirects, thanks @digininja
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTruncer committed Oct 10, 2014
1 parent 803c2e2 commit 32b5a46
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion WebTrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ def fetch(uri_str, url_list, limit = 10)
url_list.push("#{uri_str} <- Final URL")
when Net::HTTPRedirection
url_list.push("#{uri_str} redirects to...")
fetch(response['location'], url_list, limit - 1)
uri = URI.parse(uri_str)
base_url = "#{uri.scheme}://#{uri.host}"
new_url = URI.parse(response.header['location'])
if (new_url.relative?)
new_url = base_url + response.header['location']
fetch(new_url, url_list, limit - 1)
else
fetch(response['location'], url_list, limit - 1)
end
else
response.error!
end
Expand Down

0 comments on commit 32b5a46

Please sign in to comment.