Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #3936 - bundler:rebase-3833, r=indirect
Browse files Browse the repository at this point in the history
Rebase #3833

Rebases #3833 onto the latest master, allowing it to be merged.
  • Loading branch information
homu committed Aug 15, 2015
2 parents e3c73f7 + 8444564 commit d40fde7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/bundler/fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ def fetchers
@fetchers ||= FETCHERS.map {|f| f.new(downloader, remote_uri, fetch_uri, uri) }
end

def http_proxy
if uri = connection.proxy_uri
uri.to_s
else
nil
end
end

def inspect
"#<#{self.class}:0x#{object_id} uri=#{uri}>"
end
Expand Down Expand Up @@ -203,6 +211,9 @@ def connection
raise SSLError if needs_ssl && !defined?(OpenSSL::SSL)

con = Net::HTTP::Persistent.new "bundler", :ENV
if gem_proxy = Bundler.rubygems.configuration[:http_proxy]
con.proxy = URI.parse(gem_proxy)
end

if remote_uri.scheme == "https"
con.verify_mode = (Bundler.settings[:ssl_verify_mode] ||
Expand Down
26 changes: 26 additions & 0 deletions spec/bundler/fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@
allow(Bundler).to receive(:root) { Pathname.new("root") }
end

describe "#connection" do
context "when Gem.configuration doesn't specify http_proxy" do
it "specify no http_proxy" do
expect(fetcher.http_proxy).to be_nil
end
it "consider environment vars when determine proxy" do
with_env_vars("HTTP_PROXY" => "http://proxy-example.com") do
expect(fetcher.http_proxy).to match("http://proxy-example.com")
end
end
end
context "when Gem.configuration specifies http_proxy " do
before do
allow(Bundler.rubygems.configuration).to receive(:[]).and_return("http://proxy-example2.com")
end
it "consider Gem.configuration when determine proxy" do
expect(fetcher.http_proxy).to match("http://proxy-example2.com")
end
it "consider Gem.configuration when determine proxy" do
with_env_vars("HTTP_PROXY" => "http://proxy-example.com") do
expect(fetcher.http_proxy).to match("http://proxy-example2.com")
end
end
end
end

describe "#user_agent" do
it "builds user_agent with current ruby version and Bundler settings" do
allow(Bundler.settings).to receive(:all).and_return(%w[foo bar])
Expand Down
2 changes: 1 addition & 1 deletion spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def process_file(pathname)
def with_env_vars(env_hash, &block)
current_values = {}
env_hash.each do |k, v|
current_values[k] = v
current_values[k] = ENV[k]
ENV[k] = v
end
block.call if block_given?
Expand Down

0 comments on commit d40fde7

Please sign in to comment.