Class: Puppet::HTTP::Redirector Private
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Handle HTTP redirects
Instance Method Summary collapse
-
#initialize(redirect_limit) ⇒ Redirector
constructor
private
Create a new redirect handler.
-
#redirect?(request, response) ⇒ Boolean
private
Determine of the HTTP response code indicates a redirect.
-
#redirect_to(request, response, redirects) ⇒ Net::HTTP
private
Implement the HTTP request redirection.
Constructor Details
#initialize(redirect_limit) ⇒ Redirector
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new redirect handler
14 15 16 |
# File 'lib/puppet/http/redirector.rb', line 14 def initialize(redirect_limit) @redirect_limit = redirect_limit end |
Instance Method Details
#redirect?(request, response) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determine of the HTTP response code indicates a redirect
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/puppet/http/redirector.rb', line 28 def redirect?(request, response) # Net::HTTPRedirection is not used because historically puppet # has only handled these, and we're not a browser case response.code when 301, 302, 307 true else false end end |
#redirect_to(request, response, redirects) ⇒ Net::HTTP
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Implement the HTTP request redirection
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puppet/http/redirector.rb', line 51 def redirect_to(request, response, redirects) raise Puppet::HTTP::TooManyRedirects.new(request.uri) if redirects >= @redirect_limit location = parse_location(response) if location.relative? url = request.uri.dup url.path = location.path else url = location.dup end url.query = request.uri.query new_request = request.class.new(url) new_request.body = request.body request.each do |header, value| new_request[header] = value end new_request end |