Top Level Namespace
Defined Under Namespace
Modules: RedirectFollowGet
Instance Method Summary collapse
Instance Method Details
#redirect_follow_get(url, limit: 10) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/redirect_follow_get.rb', line 9 def redirect_follow_get(url, limit: 10) raise RedirectFollowGet::TooManyRedirects, 'too many HTTP redirects' if limit.zero? uri = URI(URI.escape(url)) case response = Net::HTTP.get_response(uri) when Net::HTTPSuccess response when Net::HTTPRedirection location = response['location'] redirect_follow_get(location, limit: limit - 1) else response end end |