Skip to content

Commit

Permalink
Merge pull request #222 from ampedandwired/ruby2-proxy-0.11.0
Browse files Browse the repository at this point in the history
Do not pass proxy options to Net::HTTP connection if not specified
  • Loading branch information
greatuserongithub committed Jul 16, 2013
2 parents f57a6a4 + 15ba084 commit f7b84a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/httparty/connection_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions spec/httparty/connection_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"} }
Expand Down
4 changes: 2 additions & 2 deletions spec/httparty/ssl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f7b84a9

Please sign in to comment.