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

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

    uri = 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
def proxy_from_env
    env_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']

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

    uri = 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
Creates a 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 URI is given the
 indicated user and password unless HTTP_PROXY contains either of these in
 the 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
 <tt>example.com,some.host:8080</tt>. When set to <tt>*</tt> no proxy will
 be returned.

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