Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support NO_PROXY environment variable and fix HTTP_PROXY/HTTPS_PROXY behaviour #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions common/lib/azure/storage/common/core/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 40 additions & 11 deletions test/unit/core/http_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down