Class Wrest::Native::Redirection

  1. lib/wrest/native/redirection.rb

Constructed by Wrest::Response.new if the HTTP response code is 3xx (en.wikipedia.org/wiki/300_Multiple_Choices#3xx_Redirection)

This class is necessary because Net::HTTP doesn’t seem to support redirection natively.

Methods

public instance

  1. follow

Public instance methods

follow (redirect_request_options = {})

A get is invoked on the url stored in the response headers under the key ‘location’ and the new Response is returned.

The follow_redirects_count and follow_redirects_limit options should be present. follow_redirects_count will be incremented by 1.

This method will raise a Wrest::Exceptions::AutoRedirectLimitExceeded if the follow_redirects_count equals the follow_redirects_limit.

[show source]
    # File lib/wrest/native/redirection.rb, line 27
27:       def follow(redirect_request_options = {})
28:         target = self['location']
29:         redirect_request_options = redirect_request_options.clone
30: 
31:         raise Wrest::Exceptions::AutoRedirectLimitExceeded if (redirect_request_options[:follow_redirects_count] += 1) > redirect_request_options[:follow_redirects_limit]
32: 
33:         Wrest.logger.debug "-| Redirecting to #{target}"
34:         Wrest::Uri.new(target, redirect_request_options).get
35:       end