Skip to content

Commit

Permalink
Improve Redirector options
Browse files Browse the repository at this point in the history
This preparation will meke further redirector 100% backward compatible without
any unexpected "surprises".
  • Loading branch information
ixti committed Mar 23, 2014
1 parent fb134f0 commit eeb1577
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/http/redirector.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit eeb1577

Please sign in to comment.