mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Handle status codes as strings
`Net::HTTPReponse#new` will pass through whatever you give it as the `code`, although a real `Net::HTTPResponse` status code is always a string. http://docs.ruby-lang.org/en/2.0.0/Net/HTTPResponse.html#attribute-i-code.
This commit is contained in:
parent
87af97fced
commit
e5a6edde06
2 changed files with 5 additions and 4 deletions
|
@ -282,7 +282,7 @@ module HTTParty
|
|||
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
|
||||
|
|
|
@ -26,7 +26,8 @@ module HTTParty
|
|||
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)
|
||||
|
@ -34,10 +35,10 @@ module HTTParty
|
|||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue