Top Level Namespace
Defined Under Namespace
Modules: RedirectFollowGet
Instance Method Summary collapse
Instance Method Details
#redirect_follow_get(url, limit: 10) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/redirect_follow_get.rb', line 10 def redirect_follow_get(url, limit: 10) raise RedirectFollowGet::TooManyRedirects, 'too many HTTP redirects' if limit.zero? uri = url.ascii_only? ? URI.parse(url) : Addressable::URI.parse(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 |