summaryrefslogtreecommitdiff
path: root/lib/chef/http/basic_client.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/http/basic_client.rb')
-rw-r--r--lib/chef/http/basic_client.rb51
1 files changed, 36 insertions, 15 deletions
diff --git a/lib/chef/http/basic_client.rb b/lib/chef/http/basic_client.rb
index f0f5151dbd..defa4976d1 100644
--- a/lib/chef/http/basic_client.rb
+++ b/lib/chef/http/basic_client.rb
@@ -20,10 +20,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require 'uri'
-require 'net/http'
-require 'chef/http/ssl_policies'
-require 'chef/http/http_request'
+require "uri"
+require "net/http"
+require "chef/http/ssl_policies"
+require "chef/http/http_request"
class Chef
class HTTP
@@ -72,7 +72,7 @@ class Chef
Chef::Log.debug("---- End HTTP Status/Header Data ----")
# For non-400's, log the request and response bodies
- if !response.code || !response.code.start_with?('2')
+ if !response.code || !response.code.start_with?("2")
if response.body
Chef::Log.debug("---- HTTP Response Body ----")
Chef::Log.debug(response.body)
@@ -97,15 +97,22 @@ class Chef
#adapted from buildr/lib/buildr/core/transports.rb
def proxy_uri
- proxy = Chef::Config["#{url.scheme}_proxy"]
+ proxy = Chef::Config["#{url.scheme}_proxy"] ||
+ env["#{url.scheme.upcase}_PROXY"] || env["#{url.scheme}_proxy"]
+
# Check if the proxy string contains a scheme. If not, add the url's scheme to the
- # proxy before parsing. The regex /^.*:\/\// matches, for example, http://.
- proxy = if proxy.match(/^.*:\/\//)
- URI.parse(proxy)
- else
- URI.parse("#{url.scheme}://#{proxy}")
- end if String === proxy
- excludes = Chef::Config[:no_proxy].to_s.split(/\s*,\s*/).compact
+ # proxy before parsing. The regex /^.*:\/\// matches, for example, http://. Reusing proxy
+ # here since we are really just trying to get the string built correctly.
+ if String === proxy && !proxy.strip.empty?
+ if proxy.match(/^.*:\/\//)
+ proxy = URI.parse(proxy.strip)
+ else
+ proxy = URI.parse("#{url.scheme}://#{proxy.strip}")
+ end
+ end
+
+ no_proxy = Chef::Config[:no_proxy] || env["NO_PROXY"] || env["no_proxy"]
+ excludes = no_proxy.to_s.split(/\s*,\s*/).compact
excludes = excludes.map { |exclude| exclude =~ /:\d+$/ ? exclude : "#{exclude}:*" }
return proxy unless excludes.any? { |exclude| File.fnmatch(exclude, "#{host}:#{port}") }
end
@@ -126,18 +133,32 @@ class Chef
Chef::Config
end
+ def env
+ ENV
+ end
+
def http_client_builder
http_proxy = proxy_uri
if http_proxy.nil?
Net::HTTP
else
Chef::Log.debug("Using #{http_proxy.host}:#{http_proxy.port} for proxy")
- user = Chef::Config["#{url.scheme}_proxy_user"]
- pass = Chef::Config["#{url.scheme}_proxy_pass"]
+ user = http_proxy_user(http_proxy)
+ pass = http_proxy_pass(http_proxy)
Net::HTTP.Proxy(http_proxy.host, http_proxy.port, user, pass)
end
end
+ def http_proxy_user(http_proxy)
+ http_proxy.user || Chef::Config["#{url.scheme}_proxy_user"] ||
+ env["#{url.scheme.upcase}_PROXY_USER"] || env["#{url.scheme}_proxy_user"]
+ end
+
+ def http_proxy_pass(http_proxy)
+ http_proxy.password || Chef::Config["#{url.scheme}_proxy_pass"] ||
+ env["#{url.scheme.upcase}_PROXY_PASS"] || env["#{url.scheme}_proxy_pass"]
+ end
+
def configure_ssl(http_client)
http_client.use_ssl = true
ssl_policy.apply_to(http_client)