Skip to content

Commit

Permalink
Merge pull request #432 from jpb/307-308-redirect-status-codes
Browse files Browse the repository at this point in the history
Request method is not being preserved on 307 and 308 redirects
  • Loading branch information
greatuserongithub committed Sep 21, 2015
2 parents 87af97f + e5a6edd commit 1fcea09
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/httparty/request.rb
Expand Up @@ -282,7 +282,7 @@ def handle_response(body, &block)
unless options[:maintain_method_across_redirects] && options[:resend_on_redirect]
self.http_method = Net::HTTP::Get
end
elsif last_response.code != 307 && last_response.code != 308
elsif last_response.code != '307' && last_response.code != '308'
unless options[:maintain_method_across_redirects]
self.http_method = Net::HTTP::Get
end
Expand Down
7 changes: 4 additions & 3 deletions spec/support/stub_response.rb
Expand Up @@ -26,18 +26,19 @@ def response.read_body(&block)
expect(HTTParty::Request).to receive(:new).and_return(http_request)
end

def stub_response(body, code = 200)
def stub_response(body, code = '200')
code = code.to_s
@request.options[:base_uri] ||= 'http://localhost'
unless defined?(@http) && @http
@http = Net::HTTP.new('localhost', 80)
allow(@request).to receive(:http).and_return(@http)
end

# CODE_TO_OBJ currently missing 308
if code.to_s == '308'
if code == '308'
response = Net::HTTPRedirection.new("1.1", code, body)
else
response = Net::HTTPResponse::CODE_TO_OBJ[code.to_s].new("1.1", code, body)
response = Net::HTTPResponse::CODE_TO_OBJ[code].new("1.1", code, body)
end
allow(response).to receive(:body).and_return(body)

Expand Down

0 comments on commit 1fcea09

Please sign in to comment.