class Excon::Connection
def initialize(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' -
:ciphers
(String
) -- Only use the specified SSL/TLS cipher suites; use OpenSSL cipher spec format e.g. 'HIGH:!aNULL:!3DES' or 'AES256-SHA:DES-CBC3-SHA' -
:socket
(String
) -- The path to the unix socket (required for 'unix://' connections) -
: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 -
:hostname
(String
) -- Same as host, but usable for socket connections. IPv6 addresses must not be wrapped (e.g. ::1). See URI#hostname. -
:host
(String
) -- The destination host's reachable DNS name or IP, in the form of a String. IPv6 addresses must be wrapped (e.g. [::1]). See URI#host. -
: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
def initialize(params = {}) @data = Excon.defaults.dup # merge does not deep-dup, so make sure headers is not the original @data[:headers] = @data[:headers].dup # the same goes for :middlewares @data[:middlewares] = @data[:middlewares].dup params = validate_params(:connection, params) @data.merge!(params) setup_proxy if ENV.has_key?('EXCON_STANDARD_INSTRUMENTOR') @data[:instrumentor] = Excon::StandardInstrumentor end if @data[:debug] || ENV.has_key?('EXCON_DEBUG') @data[:debug_request] = @data[:debug_response] = true @data[:instrumentor] = Excon::StandardInstrumentor end # Use Basic Auth if url contains a login if @data[:user] || @data[:password] user, pass = Utils.unescape_form(@data[:user].to_s), Utils.unescape_form(@data[:password].to_s) @data[:headers]['Authorization'] ||= 'Basic ' << ['' << user.to_s << ':' << pass.to_s].pack('m').delete(Excon::CR_NL) end @socket_key = '' << @data[:scheme] if @data[:scheme] == UNIX if @data[:host] raise ArgumentError, "The `:host` parameter should not be set for `unix://` connections.\n" + "When supplying a `unix://` URI, it should start with `unix:/` or `unix:///`." elsif !@data[:socket] raise ArgumentError, 'You must provide a `:socket` for `unix://` connections' else @socket_key << '://' << @data[:socket] end else @socket_key << '://' << @data[:host] << port_string(@data) end reset end