Class: HTTP::Redirector

Inherits:
Object
  • Object
show all
Defined in:
lib/http/redirector.rb

Defined Under Namespace

Classes: EndlessRedirectError, TooManyRedirectsError

Constant Summary collapse

REDIRECT_CODES =

HTTP status codes which indicate redirects

[300, 301, 302, 303, 307, 308].freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Redirector

:nodoc:


13
14
15
16
17
# File 'lib/http/redirector.rb', line 13

def initialize(options = nil)
  options   = {:max_hops => 5} unless options.respond_to?(:fetch)
  @max_hops = options.fetch(:max_hops, 5)
  @max_hops = false if @max_hops && 1 > @max_hops.to_i
end

Instance Method Details

#perform(request, response, &block) ⇒ Object

Follows redirects until non-redirect response found


20
21
22
23
# File 'lib/http/redirector.rb', line 20

def perform(request, response, &block)
  reset(request, response)
  follow(&block)
end