Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Redirects #56

Closed
wants to merge 1 commit into from

2 participants

@rkj

Hi!
I had problems with login to a site. First problem was that httparty didn't follow relative redirects. According to: http://en.wikipedia.org/wiki/HTTP_location it should be always absolute uri, but some sites do not follow this...
Second problem I've had was that after redirecting I didn't see the cookie site was setting. I have added option :follow_redirect to disable redirecting so I can see Set-Cookie header on the original response.
Best regards,
Roman

Roman Kamyk * Added options :follow_redirects.
* Added following of relative redirects.
d5b42e6
@sandro
Collaborator

Thanks for the patch, I'll try to get it in soon.

@sandro
Collaborator

Refactor redirection handling

Closed by 7ea359d

@ntalbott ntalbott referenced this pull request from a commit in ntalbott/httparty
@sandro sandro Refactor redirection handling
Closes gh-56
7ea359d
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 10, 2010
  1. * Added options :follow_redirects.

    Roman Kamyk authored
    * Added following of relative redirects.
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 7 deletions.
  1. +10 −7 lib/httparty/request.rb
View
17 lib/httparty/request.rb
@@ -19,6 +19,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
@@ -178,19 +179,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(last_response, parse_response(last_response.body))
end
+ Response.new(last_response, parse_response(last_response.body))
end
# Inspired by Ruby 1.9
Something went wrong with that request. Please try again.