зеркало из https://github.com/github/ruby.git
Allow Net::HTTP to fetch user/pass from http_proxy
Note that this feature is enabled only on environment variables are multi-user safe. In this time the list includes Linux, FreeBSD, or Darwin. [Bug #12921] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58461 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
ece9698d73
Коммит
c7ec1b1f59
5
NEWS
5
NEWS
|
@ -55,6 +55,11 @@ with all sufficient information, see the ChangeLog file or Redmine
|
|||
|
||||
=== Stdlib updates (outstanding ones only)
|
||||
|
||||
* Net::HTTP
|
||||
* Net::HTTP#proxy_user and Net::HTTP#proxy_pass now reflects http_proxy
|
||||
environment variable if the system's environment variable is multiuser
|
||||
safe. [Bug #12921]
|
||||
|
||||
* RbConfig
|
||||
* New constants:
|
||||
* RbConfig::LIMITS is added to provide the limits of C types.
|
||||
|
|
|
@ -1080,14 +1080,29 @@ module Net #:nodoc:
|
|||
end
|
||||
end
|
||||
|
||||
# The proxy username, if one is configured
|
||||
def proxy_user
|
||||
@proxy_user
|
||||
# [Bug #12921]
|
||||
if /linux|freebsd|darwin/ =~ RUBY_PLATFORM
|
||||
ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE = true
|
||||
else
|
||||
ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE = false
|
||||
end
|
||||
|
||||
# The proxy password, if one is configured
|
||||
# The username of the proxy server, if one is configured.
|
||||
def proxy_user
|
||||
if ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE && @proxy_from_env
|
||||
proxy_uri&.user
|
||||
else
|
||||
@proxy_user
|
||||
end
|
||||
end
|
||||
|
||||
# The password of the proxy server, if one is configured.
|
||||
def proxy_pass
|
||||
@proxy_pass
|
||||
if ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE && @proxy_from_env
|
||||
proxy_uri&.password
|
||||
else
|
||||
@proxy_pass
|
||||
end
|
||||
end
|
||||
|
||||
alias proxyaddr proxy_address #:nodoc: obsolete
|
||||
|
|
|
@ -134,6 +134,23 @@ class TestNetHTTP < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_proxy_eh_ENV_with_user
|
||||
clean_http_proxy_env do
|
||||
ENV['http_proxy'] = 'http://foo:bar@proxy.example:8000'
|
||||
|
||||
http = Net::HTTP.new 'hostname.example'
|
||||
|
||||
assert_equal true, http.proxy?
|
||||
if Net::HTTP::ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE
|
||||
assert_equal 'foo', http.proxy_user
|
||||
assert_equal 'bar', http.proxy_pass
|
||||
else
|
||||
assert_nil http.proxy_user
|
||||
assert_nil http.proxy_pass
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_proxy_eh_ENV_none_set
|
||||
clean_http_proxy_env do
|
||||
assert_equal false, Net::HTTP.new('hostname.example').proxy?
|
||||
|
|
Загрузка…
Ссылка в новой задаче