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 = { :connect_timeout => 60, :headers => {}, :host => uri.host, :instrumentor_name => 'excon', :mock => Excon.instance_variable_get(:@mock), :path => uri.path, :port => uri.port.to_s, :query => uri.query, :read_timeout => 60, :retry_limit => DEFAULT_RETRY_LIMIT, :scheme => uri.scheme, :write_timeout => 60 }.merge!(params) # 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 @socket_key = '' << @connection[:host] << ':' << @connection[:port] reset end