Permalink
Browse files

* Added options :follow_redirects.

* Added following of relative redirects.
  • Loading branch information...
1 parent 71d6455 commit def1d461e8182cf870f193be9bd310ce1d9f4e96 Roman Kamyk committed with sandro Dec 10, 2010
Showing with 10 additions and 7 deletions.
  1. +10 −7 lib/httparty/request.rb
@@ -31,6 +31,7 @@ def initialize(http_method, path, o={})
self.options = {
:limit => o.delete(:no_follow) ? 1 : 5,
:default_params => {},
+ :follow_redirects => true,
:parser => Parser
}.merge(o)
end
@@ -190,19 +191,21 @@ def handle_response
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

0 comments on commit def1d46

Please sign in to comment.