Class: Wrest::Native::Redirection
- Defined in:
- lib/wrest/native/redirection.rb
Overview
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.
Instance Attribute Summary
Attributes inherited from Response
#deserialised_body, #http_response
Instance Method Summary collapse
-
#follow(redirect_request_options = {}) ⇒ Object
A get is invoked on the url stored in the response headers under the key ‘location’ and the new Response is returned.
Methods inherited from Response
#==, #cache_control_headers, #cacheable?, #can_be_validated?, #code_cacheable?, #connection_closed?, #current_age, #deserialise, #deserialise_using, #deserialize, #deserialize_using, #expired?, #expires, #expires_not_in_its_past?, #expires_not_in_our_past?, #freshness_lifetime, #hash, #headers, #initialize, #initialize_copy, #last_modified, #max_age, new, #no_cache_flag_not_set?, #no_store_flag_not_set?, #parse_datefield, #pragma_nocache_not_set?, #recalculate_cache_control_headers, #recalculate_freshness_lifetime, #response_date, #vary_header_valid?
Methods included from HttpCodes
#accepted?, #bad_request?, #created?, #forbidden?, #found?, #internal_server_error?, #method_not_allowed?, #moved_permanently?, #no_content?, #not_acceptable?, #not_found?, #not_modified?, #ok?, #see_other?, #temporary_redirect?, #unauthorized?, #unprocessable_entity?
Constructor Details
This class inherits a constructor from Wrest::Native::Response
Instance Method Details
#follow(redirect_request_options = {}) ⇒ Object
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.
28 29 30 31 32 33 34 35 36 |
# File 'lib/wrest/native/redirection.rb', line 28 def follow( = {}) target = self['location'] = .clone raise Wrest::Exceptions::AutoRedirectLimitExceeded if ([:follow_redirects_count] += 1) > [:follow_redirects_limit] Wrest.logger.debug "-| Redirecting to #{target}" Wrest::Uri.new(target, ).get end |