diff --git a/lib/httparty/connection_adapter.rb b/lib/httparty/connection_adapter.rb index 2339f2bd..469a58b8 100644 --- a/lib/httparty/connection_adapter.rb +++ b/lib/httparty/connection_adapter.rb @@ -66,7 +66,11 @@ def initialize(uri, options={}) def connection host = clean_host(uri.host) - http = Net::HTTP.new(host, uri.port, options[:http_proxyaddr], options[:http_proxyport], options[:http_proxyuser], options[:http_proxypass]) + if options[:http_proxyaddr] + http = Net::HTTP.new(host, uri.port, options[:http_proxyaddr], options[:http_proxyport], options[:http_proxyuser], options[:http_proxypass]) + else + http = Net::HTTP.new(host, uri.port) + end http.use_ssl = ssl_implied?(uri) diff --git a/spec/httparty/connection_adapter_spec.rb b/spec/httparty/connection_adapter_spec.rb index 210f6554..b5325192 100644 --- a/spec/httparty/connection_adapter_spec.rb +++ b/spec/httparty/connection_adapter_spec.rb @@ -176,6 +176,16 @@ end end + context 'when not providing a proxy address' do + let(:uri) { URI 'http://proxytest.com' } + + it "does not pass any proxy parameters to the connection" do + http = Net::HTTP.new("proxytest.com") + Net::HTTP.should_receive(:new).once.with("proxytest.com", 80).and_return(http) + adapter.connection + end + end + context "when providing PEM certificates" do let(:pem) { :pem_contents } let(:options) { {:pem => pem, :pem_password => "password"} } diff --git a/spec/httparty/ssl_spec.rb b/spec/httparty/ssl_spec.rb index 221c4c94..512762ba 100644 --- a/spec/httparty/ssl_spec.rb +++ b/spec/httparty/ssl_spec.rb @@ -27,10 +27,10 @@ end it "should work when using ssl_ca_path with a certificate authority" do - http = Net::HTTP.new('www.google.com', 443, nil, nil, nil, nil) + http = Net::HTTP.new('www.google.com', 443) response = stub(Net::HTTPResponse, :[] => '', :body => '', :to_hash => {}) http.stub(:request).and_return(response) - Net::HTTP.should_receive(:new).with('www.google.com', 443, nil, nil, nil, nil).and_return(http) + Net::HTTP.should_receive(:new).with('www.google.com', 443).and_return(http) http.should_receive(:ca_path=).with('/foo/bar') HTTParty.get('https://www.google.com', :ssl_ca_path => '/foo/bar') end