class Excon::Connection
def setup_proxy
def setup_proxy if @data[:disable_proxy] if @data[:proxy] raise ArgumentError, "`:disable_proxy` parameter and `:proxy` parameter cannot both be set at the same time." end return end return if @data[:scheme] == UNIX proxy_from_env case @data[:proxy] when nil @data.delete(:proxy) when '' @data.delete(:proxy) when Hash # no processing needed when String, URI uri = @data[:proxy].is_a?(String) ? URI.parse(@data[:proxy]) : @data[:proxy] @data[:proxy] = { :host => uri.host, :hostname => uri.hostname, # path is only sensible for a Unix socket proxy :path => uri.scheme == UNIX ? uri.path : nil, :port => uri.port, :scheme => uri.scheme, } if uri.password @data[:proxy][:password] = uri.password end if uri.user @data[:proxy][:user] = uri.user end if @data[:ssl_proxy_headers] && !@data[:ssl_uri_schemes].include?(@data[:scheme]) raise ArgumentError, "The `:ssl_proxy_headers` parameter should only be used with HTTPS requests." end if @data[:proxy][:scheme] == UNIX if @data[:proxy][:host] raise ArgumentError, "The `:host` parameter should not be set for `unix://` proxies.\n" + "When supplying a `unix://` URI, it should start with `unix:/` or `unix:///`." end else unless uri.host && uri.port && uri.scheme raise Excon::Errors::ProxyParse, "Proxy is invalid" end end else raise Excon::Errors::ProxyParse, "Proxy is invalid" end if @data.has_key?(:proxy) && @data[:scheme] == 'http' @data[:headers]['Proxy-Connection'] ||= 'Keep-Alive' # https credentials happen in handshake if @data[:proxy].has_key?(:user) || @data[:proxy].has_key?(:password) user, pass = Utils.unescape_form(@data[:proxy][:user].to_s), Utils.unescape_form(@data[:proxy][:password].to_s) auth = ["#{user}:#{pass}"].pack('m').delete(Excon::CR_NL) @data[:headers]['Proxy-Authorization'] = 'Basic ' + auth end end end