summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--lib/net/http.rb23
-rw-r--r--test/net/http/test_http.rb17
3 files changed, 41 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index cdb75cc7d9..5ef0bfb112 100644
--- a/NEWS
+++ b/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.
diff --git a/lib/net/http.rb b/lib/net/http.rb
index 5a22fc0015..c648f0acc4 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -1080,14 +1080,29 @@ module Net #:nodoc:
end
end
- # The proxy username, if one is configured
+ # [Bug #12921]
+ if /linux|freebsd|darwin/ =~ RUBY_PLATFORM
+ ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE = true
+ else
+ ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE = false
+ end
+
+ # The username of the proxy server, if one is configured.
def proxy_user
- @proxy_user
+ if ENVIRONMENT_VARIABLE_IS_MULTIUSER_SAFE && @proxy_from_env
+ proxy_uri&.user
+ else
+ @proxy_user
+ end
end
- # The proxy password, if one is configured
+ # 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
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb
index f2c03f2915..7db5909f96 100644
--- a/test/net/http/test_http.rb
+++ b/test/net/http/test_http.rb
@@ -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?