vendored/puppet/lib/puppet/util/http_proxy.rb in bolt-0.15.0 vs vendored/puppet/lib/puppet/util/http_proxy.rb in bolt-0.16.0

- old
+ new

@@ -1,7 +1,8 @@ require 'uri' require 'openssl' +require 'puppet/network/http' module Puppet::Util::HttpProxy def self.proxy(uri) if self.no_proxy?(uri) proxy_class = Net::HTTP::Proxy(nil) @@ -170,22 +171,29 @@ current_uri = uri response = nil 0.upto(redirect_limit) do |redirection| proxy = get_http_object(current_uri) - response = proxy.send(:head, current_uri.path) + headers = { 'Accept' => '*/*', 'User-Agent' => Puppet[:http_user_agent] } + if Puppet.features.zlib? + headers.merge!({"Accept-Encoding" => Puppet::Network::HTTP::Compression::ACCEPT_ENCODING}) + end + + response = proxy.send(:head, current_uri.path, headers) + if [301, 302, 307].include?(response.code.to_i) # handle the redirection current_uri = URI.parse(response['location']) next end - if block_given? - headers = {'Accept' => 'binary', 'accept-encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3'} - response = proxy.send("request_#{method}".to_sym, current_uri.path, headers, &block) - else - response = proxy.send(method, current_uri.path) + if method != :head + if block_given? + response = proxy.send("request_#{method}".to_sym, current_uri.path, headers, &block) + else + response = proxy.send(method, current_uri.path, headers) + end end Puppet.debug("HTTP #{method.to_s.upcase} request to #{current_uri} returned #{response.code} #{response.message}") return response