Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Do not HEAD on POST request with digest authentication

  • Loading branch information...
commit fbde7f1d0fc2003a0af6bebfc49e8fe3624a02b8 1 parent c87774f
@txus txus authored committed
Showing with 16 additions and 1 deletion.
  1. +5 −1 lib/httparty/request.rb
  2. +11 −0 spec/httparty/request_spec.rb
View
6 lib/httparty/request.rb
@@ -160,7 +160,11 @@ def setup_raw_request
end
def setup_digest_auth
- res = http.head(uri.request_uri, options[:headers])
+ if @raw_request.class == Net::HTTP::Get || @raw_request.class == Net::HTTP::Head
+ res = http.head(uri.request_uri, options[:headers])
+ else
+ res = self.last_response = http.request(@raw_request)
+ end
if res['www-authenticate'] != nil && res['www-authenticate'].length > 0
@raw_request.digest_auth(username, password, res)
end
View
11 spec/httparty/request_spec.rb
@@ -95,6 +95,17 @@
raw_request = @request.instance_variable_get(:@raw_request)
raw_request.instance_variable_get(:@header)['Authorization'].should_not be_nil
end
+
+ it "should use the right http method for digest authentication" do
+ @post_request = HTTParty::Request.new(Net::HTTP::Post, 'http://api.foo.com/v1', :format => :xml)
+ FakeWeb.register_uri(:post, "http://api.foo.com/v1", {})
+
+ http = @post_request.send(:http)
+ @post_request.should_receive(:http).and_return(http)
+ http.should_not_receive(:head).and_return({'www-authenticate' => nil})
+ @post_request.options[:digest_auth] = {:username => 'foobar', :password => 'secret'}
+ @post_request.send(:setup_raw_request)
+ end
end
describe "#uri" do
Please sign in to comment.
Something went wrong with that request. Please try again.