diff --git a/common/lib/azure/storage/common/core/http_client.rb b/common/lib/azure/storage/common/core/http_client.rb index 4fdc06f4..a1dc3306 100644 --- a/common/lib/azure/storage/common/core/http_client.rb +++ b/common/lib/azure/storage/common/core/http_client.rb @@ -65,12 +65,7 @@ def build_http(uri) ssl_options[:ca_file] = self.ca_file if self.ca_file ssl_options[:verify] = true end - proxy_options = if ENV["HTTP_PROXY"] - URI::parse(ENV["HTTP_PROXY"]) - elsif ENV["HTTPS_PROXY"] - URI::parse(ENV["HTTPS_PROXY"]) - end || nil - Faraday.new(uri, ssl: ssl_options, proxy: proxy_options) do |conn| + Faraday.new(uri, ssl: ssl_options) do |conn| conn.use FaradayMiddleware::FollowRedirects conn.adapter :net_http_persistent, pool_size: 5 do |http| # yields Net::HTTP::Persistent diff --git a/test/unit/core/http_client_test.rb b/test/unit/core/http_client_test.rb index 1133400d..33cf4e81 100644 --- a/test/unit/core/http_client_test.rb +++ b/test/unit/core/http_client_test.rb @@ -3,9 +3,8 @@ describe Azure::Storage::Common::Core::HttpClient do subject { Azure::Storage } - let :uri do - URI("https://management.core.windows.net") - end + let(:uri) { URI("https://management.core.windows.net") } + let(:proxy_uri) { URI("http://localhost:3128") } describe "#agents" do describe "reusing a connection when connecting to the same host" do @@ -33,34 +32,64 @@ end describe "when using a http proxy" do - let(:http_proxy_uri) { URI("http://localhost:80") } - before do - ENV["HTTP_PROXY"] = http_proxy_uri.to_s + ENV["HTTP_PROXY"] = proxy_uri.to_s end after do ENV["HTTP_PROXY"] = nil end - it "should set the proxy configuration information on the http connection" do - _(Azure::Storage::Common::Client::create.agents(uri).proxy.uri).must_equal http_proxy_uri + it "should not set the proxy configuration information if only a http is configured" do + _(Azure::Storage::Common::Client::create.agents(uri).proxy).must_be_nil end end describe "when using a https proxy" do - let(:https_proxy_uri) { URI("https://localhost:443") } + before do + ENV["HTTPS_PROXY"] = proxy_uri.to_s + end + + after do + ENV["HTTPS_PROXY"] = nil + end + + it "should set the proxy configuration information on the https connection" do + _(Azure::Storage::Common::Client::create.agents(uri).proxy.uri).must_equal proxy_uri + end + end + + describe "when using a https proxy with no_proxy containing the URL" do + let(:https_proxy_uri) { URI("http://localhost:3128") } before do ENV["HTTPS_PROXY"] = https_proxy_uri.to_s + ENV["NO_PROXY"] = "localhost,.windows.net" end after do ENV["HTTPS_PROXY"] = nil + ENV["NO_PROXY"] = nil end - it "should set the proxy configuration information on the https connection" do - _(Azure::Storage::Common::Client::create.agents(uri).proxy.uri).must_equal https_proxy_uri + it "should not set the proxy configuration because of the NO_PROXY" do + _(Azure::Storage::Common::Client::create.agents(uri).proxy).must_be_nil + end + end + + describe "when using a https proxy with no_proxy that doesn't contain the URL" do + before do + ENV["HTTPS_PROXY"] = proxy_uri.to_s + ENV["NO_PROXY"] = "localhost,.microsoft.net" + end + + after do + ENV["HTTPS_PROXY"] = nil + ENV["NO_PROXY"] = nil + end + + it "should not set the proxy configuration because of the NO_PROXY" do + _(Azure::Storage::Common::Client::create.agents(uri).proxy.uri).must_equal proxy_uri end end end