ruby-changes:46348
From: naruse <ko1@a...>
Date: Mon, 24 Apr 2017 01:19:29 +0900 (JST)
Subject: [ruby-changes:46348] naruse:r58461 (trunk): Allow Net::HTTP to fetch user/pass from http_proxy
naruse 2017-04-24 01:19:23 +0900 (Mon, 24 Apr 2017) New Revision: 58461 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58461 Log: 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] Modified files: trunk/NEWS trunk/lib/net/http.rb trunk/test/net/http/test_http.rb Index: lib/net/http.rb =================================================================== --- lib/net/http.rb (revision 58460) +++ lib/net/http.rb (revision 58461) @@ -1080,14 +1080,29 @@ module Net #:nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L1080 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 Index: NEWS =================================================================== --- NEWS (revision 58460) +++ NEWS (revision 58461) @@ -55,6 +55,11 @@ with all sufficient information, see the https://github.com/ruby/ruby/blob/trunk/NEWS#L55 === 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. Index: test/net/http/test_http.rb =================================================================== --- test/net/http/test_http.rb (revision 58460) +++ test/net/http/test_http.rb (revision 58461) @@ -134,6 +134,23 @@ class TestNetHTTP < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/http/test_http.rb#L134 end end + def test_proxy_eh_ENV_with_user + clean_http_proxy_env do + ENV['http_proxy'] = 'http://foo:bar@p...: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? -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/