mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
ece9698d73
commit
c7ec1b1f59
3 changed files with 42 additions and 5 deletions
5
NEWS
5
NEWS
|
@ -55,6 +55,11 @@ with all sufficient information, see the ChangeLog file or Redmine
|
||||||
|
|
||||||
=== Stdlib updates (outstanding ones only)
|
=== 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
|
* RbConfig
|
||||||
* New constants:
|
* New constants:
|
||||||
* RbConfig::LIMITS is added to provide the limits of C types.
|
* RbConfig::LIMITS is added to provide the limits of C types.
|
||||||
|
|
|
@ -1080,14 +1080,29 @@ module Net #:nodoc:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The proxy username, if one is configured
|
# [Bug #12921]
|
||||||
def proxy_user
|
if /linux|freebsd|darwin/ =~ RUBY_PLATFORM
|
||||||
@proxy_user
|
ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE = true
|
||||||
|
else
|
||||||
|
ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE = false
|
||||||
end
|
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
|
def proxy_pass
|
||||||
@proxy_pass
|
if ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE && @proxy_from_env
|
||||||
|
proxy_uri&.password
|
||||||
|
else
|
||||||
|
@proxy_pass
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
alias proxyaddr proxy_address #:nodoc: obsolete
|
alias proxyaddr proxy_address #:nodoc: obsolete
|
||||||
|
|
|
@ -134,6 +134,23 @@ class TestNetHTTP < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
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
|
def test_proxy_eh_ENV_none_set
|
||||||
clean_http_proxy_env do
|
clean_http_proxy_env do
|
||||||
assert_equal false, Net::HTTP.new('hostname.example').proxy?
|
assert_equal false, Net::HTTP.new('hostname.example').proxy?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue