Module: RestClient::AbstractResponse

Defined in:
lib/rest-core/patch/rest-client.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) follow_redirection(request = nil, result = nil, &block)

Follow a redirection



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rest-core/patch/rest-client.rb', line 10

def follow_redirection request = nil, result = nil, & block
  url = headers[:location]
  if url !~ /^http/
    url = URI.parse(args[:url]).merge(url).to_s
  end
  args[:url] = url
  if request
    if request.max_redirects == 0
      # begin patch
      # https://github.com/archiloque/rest-client/pull/118
      raise MaxRedirectsReached.new(self, code)
      # end patch
    end
    args[:password] = request.password
    args[:user] = request.user
    args[:headers] = request.headers
    args[:max_redirects] = request.max_redirects - 1
    # pass any cookie set in the result
    if result && result['set-cookie']
      args[:headers][:cookies] = (args[:headers][:cookies] || {}).merge(parse_cookie(result['set-cookie']))
    end
  end
  Request.execute args, &block
end