Method: Gem::Net::HTTP::Persistent#proxy_from_env

Defined in:
lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb

#proxy_from_envObject

Creates a Gem::URI for an HTTP proxy server from ENV variables.

If HTTP_PROXY is set a proxy will be returned.

If HTTP_PROXY_USER or HTTP_PROXY_PASS are set the Gem::URI is given the indicated user and password unless HTTP_PROXY contains either of these in the Gem::URI.

The NO_PROXY ENV variable can be used to specify hosts which shouldn’t be reached via proxy; if set it should be a comma separated list of hostname suffixes, optionally with :port appended, for example example.com,some.host:8080. When set to * no proxy will be returned.

For Windows users, lowercase ENV variables are preferred over uppercase ENV variables.



837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
# File 'lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb', line 837

def proxy_from_env
  env_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']

  return nil if env_proxy.nil? or env_proxy.empty?

  uri = Gem::URI normalize_uri env_proxy

  env_no_proxy = ENV['no_proxy'] || ENV['NO_PROXY']

  # '*' is special case for always bypass
  return nil if env_no_proxy == '*'

  if env_no_proxy then
    uri.query = "no_proxy=#{escape(env_no_proxy)}"
  end

  unless uri.user or uri.password then
    uri.user     = escape ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER']
    uri.password = escape ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS']
  end

  uri
end