From eeb1577db5e8f29ca9d20ba27fdb9b7c851eaf29 Mon Sep 17 00:00:00 2001 From: Aleksey V Zapparov Date: Sun, 23 Mar 2014 23:31:52 +0100 Subject: [PATCH] Improve Redirector options This preparation will meke further redirector 100% backward compatible without any unexpected "surprises". --- lib/http/redirector.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/http/redirector.rb b/lib/http/redirector.rb index 9720d538..d2ec0636 100644 --- a/lib/http/redirector.rb +++ b/lib/http/redirector.rb @@ -10,8 +10,9 @@ class EndlessRedirectError < TooManyRedirectsError; end REDIRECT_CODES = [300, 301, 302, 303, 307, 308].freeze # :nodoc: - def initialize(max_redirects) - @max_redirects = max_redirects + def initialize(options = nil) + options = {:max_hops => 5} unless options.respond_to?(:fetch) + @max_hops = options.fetch(:max_hops, 5) end # Follows redirects until non-redirect response found @@ -53,13 +54,11 @@ def follow # Check if we reached max amount of redirect hops def too_many_hops? - return false if @max_redirects.is_a?(TrueClass) - @max_redirects.to_i < @visited.count + @max_hops.to_i < @visited.count if @max_hops end # Check if we got into an endless loop def endless_loop? - # pretty naive condition 2 < @visited.count(@visited.last) end end