class Excon::Connection

def initialize(params = {})

Options Hash: (**params)
  • :instrumentor_name (String) -- Name prefix for #instrument events. Defaults to 'excon'
  • :instrumentor (Class) -- Responds to #instrument as in ActiveSupport::Notifications
  • :retry_interval (Fixnum) -- Set how long to wait between retries. (Default 0)
  • :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 = {})
  @pid = Process.pid
  @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
  @data.merge!(params)
  validate_params(:connection, @data, @data[:middlewares])
  if @data.key?(:host) && !@data.key?(:hostname)
    Excon.display_warning('hostname is missing! For IPv6 support, provide both host and hostname: Excon::Connection#new(:host => uri.host, :hostname => uri.hostname, ...).')
    @data[:hostname] = @data[:host]
  end
  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
  if @data[:scheme] == UNIX
    # 'uri' >= v0.12.0 returns an empty string instead of nil for no host.
    # So treat the parameter as present if and only if it is both non-nill and non-empty.
    if @data[:host] && !@data[:host].empty?
      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[:scheme]}://#{@data[:socket]}"
    end
  else
    @socket_key = "#{@data[:scheme]}://#{@data[:host]}#{port_string(@data)}"
  end
  reset
end