Skip to content

Commit

Permalink
Do not HEAD on POST request with digest authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Josep M. Bach authored and jnunemaker committed Apr 12, 2012
1 parent c87774f commit fbde7f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/httparty/request.rb
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/httparty/request_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit fbde7f1

Please sign in to comment.