Class: HTTP::Redirector

### Home Classes Methods

### In Files

- lib/http/redirector.rb

### Parent

Object

### Namespace

- CLASS HTTP::Redirector::EndlessRedirectError
- CLASS HTTP::Redirector::TooManyRedirectsError

### Methods

- ::new
- #perform

### Class/Module Index

Quicksearch

- HTTP
- HTTP::Cache
- HTTP::Cache::Headers
- HTTP::Cache::NullCache
- HTTP::Cache::NullLogger
- HTTP::CacheError
- HTTP::Chainable
- HTTP::Client
- HTTP::Connection
- HTTP::Error
- HTTP::Headers
- HTTP::Headers::Mixin
- HTTP::InvalidHeaderNameError
- HTTP::MimeType
- HTTP::MimeType::Adapter
- HTTP::MimeType::JSON
- HTTP::Options
- HTTP::Redirector
- HTTP::Redirector::EndlessRedirectError
- HTTP::Redirector::TooManyRedirectsError
- HTTP::Request
- HTTP::Request::Caching
- HTTP::Request::UnsupportedMethodError
- HTTP::Request::UnsupportedSchemeError
- HTTP::Request::Writer
- HTTP::RequestError
- HTTP::Response
- HTTP::Response::Body
- HTTP::Response::Caching
- HTTP::Response::IoBody
- HTTP::Response::Parser
- HTTP::Response::Status
- HTTP::Response::StringBody
- HTTP::ResponseError
- HTTP::StateError
- HTTP::Timeout
- HTTP::Timeout::Global
- HTTP::Timeout::Null
- HTTP::Timeout::PerOperation
- HTTP::TimeoutError
- HTTP::URI
- Object

No matching classes.

# HTTP::Redirector

### Constants

REDIRECT_CODES

  HTTP status codes which indicate redirects

SEE_OTHER_ALLOWED_VERBS

  Verbs which will remain unchanged upon See Other response.

STRICT_SENSITIVE_CODES

  Codes which which should raise StateError in strict mode if original request was any of {UNSAFE_VERBS}

UNSAFE_VERBS

  Insecure http verbs, which should trigger StateError in strict mode upon {STRICT_SENSITIVE_CODES}

### Attributes

max_hops[R]

@!attribute [r] max_hops

    Returns maximum allowed hops.
    @return [Fixnum]

strict[R]

@!attribute [r] strict

    Returns redirector policy.
    @return [Boolean]

### Public Class Methods

new(opts = {}) click to toggle source

@param [Hash] opts @option opts [Boolean] :strict (true) redirector hops policy @option opts [to_i] :max_hops (5) maximum allowed amount of hops

    # File lib/http/redirector.rb, line 40
    def initialize(opts = {})
      @strict   = opts.fetch(:strict, true)
      @max_hops = opts.fetch(:max_hops, 5).to_i
    end

### Public Instance Methods

perform(request, response) click to toggle source

Follows redirects until non-redirect response found

    # File lib/http/redirector.rb, line 46
    def perform(request, response)
      @request  = request
      @response = response
      @visited  = []

      while REDIRECT_CODES.include? @response.status.code
        @visited << "#{@request.verb} #{@request.uri}"

        fail TooManyRedirectsError if too_many_hops?
        fail EndlessRedirectError  if endless_loop?

        @request  = redirect_to @response.headers[Headers::LOCATION]
        @response = yield @request
      end

      @response
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.