1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

* Added options :follow_redirects.

* Added following of relative redirects.
This commit is contained in:
Roman Kamyk 2010-12-10 11:32:51 +01:00 committed by Sandro Turriate
parent 71d6455a04
commit def1d461e8

View file

@ -31,6 +31,7 @@ module HTTParty
self.options = {
:limit => o.delete(:no_follow) ? 1 : 5,
:default_params => {},
:follow_redirects => true,
:parser => Parser
}.merge(o)
end
@ -190,19 +191,21 @@ module HTTParty
Net::HTTPSeeOther, # 303
Net::HTTPUseProxy, # 305
Net::HTTPTemporaryRedirect
if last_response.key?('location')
if options[:follow_redirects] && last_response.key?('location')
options[:limit] -= 1
self.path = last_response['location']
new_uri = last_response['location']
if new_uri =~ /^http/
self.path = new_uri
else
self.path.merge(new_uri)
end
self.redirect = true
self.http_method = Net::HTTP::Get unless options[:maintain_method_across_redirects]
capture_cookies(last_response)
perform
else
last_response
return perform
end
else
Response.new(self, last_response, parse_response(last_response.body))
end
Response.new(self, last_response, parse_response(last_response.body))
end
# Inspired by Ruby 1.9