class Excon::Connection
def initialize(url, params = {})
(**params)
-
:instrumentor_name
(String
) -- Name prefix for #instrument events. Defaults to 'excon' -
:instrumentor
(Class
) -- Responds to #instrument as in ActiveSupport::Notifications -
:retry_limit
(Fixnum
) -- Set how many times we'll retry a failed request. (Default 4) -
:proxy
(String
) -- Proxy server; e.g. 'http://myproxy.com:8888' -
:scheme
(String
) -- The protocol; 'https' causes OpenSSL to be used -
:query
(Hash
) -- Default query; appended to the 'scheme://host:port/path/' in the form of '?key=value'. Will only be used if params[:query] is not supplied to Connection#request -
:port
(Fixnum
) -- The port on which to connect, to the destination host -
:path
(String
) -- Default path; appears after 'scheme://host:port/'. Only used if params[:path] is not supplied to Connection#request -
:host
(String
) -- The destination host's reachable DNS name or IP, in the form of a String -
:headers
(Hash
) -- The default headers to supply in a request. Only used if params[:headers] is not supplied to Connection#request -
:body
(String
) -- Default text to be sent over a socket. Only used if :body absent in Connection#request params
Parameters:
-
params
(Hash
) -- One or more optional params -
url
(String
) -- The destination URL
def initialize(url, params = {}) uri = URI.parse(url) @connection = Excon.defaults.merge({ :host => uri.host, :path => uri.path, :port => uri.port.to_s, :query => uri.query, :scheme => uri.scheme, }).merge!(params) # merge does not deep-dup, so make sure headers is not the original @connection[:headers] = @connection[:headers].dup @proxy = nil # use proxy from the environment if present if ENV.has_key?('http_proxy') @proxy = setup_proxy(ENV['http_proxy']) elsif params.has_key?(:proxy) @proxy = setup_proxy(params[:proxy]) end if @connection[:scheme] == HTTPS # use https_proxy if that has been specified if ENV.has_key?('https_proxy') @proxy = setup_proxy(ENV['https_proxy']) end end if @proxy @connection[:headers]['Proxy-Connection'] ||= 'Keep-Alive' end # Use Basic Auth if url contains a login if uri.user || uri.password auth = ["#{uri.user}:#{uri.password}"].pack('m').delete("\r\n") @connection[:headers]['Authorization'] ||= "Basic #{auth}" end @socket_key = '' << @connection[:host] << ':' << @connection[:port] reset end