class Excon::Connection

def request(params, &block)

Options Hash: (**params)
  • :scheme (String) -- The protocol; 'https' causes OpenSSL to be used
  • :query (Hash) -- appended to the 'scheme://host:port/path/' in the form of '?key=value'
  • :port (Fixnum) -- The port on which to connect, to the destination host
  • :path (String) -- appears after 'scheme://host:port/'
  • :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
  • :body (String) -- text to be sent over a socket

Parameters:
  • params (Hash) -- One or more optional params, override defaults set in Connection.new

Other tags:
    Yield: - @see Response#self.parse
def request(params, &block)
  # connection has defaults, merge in new params to override
  params = @connection.merge(params)
  params[:headers] = @connection[:headers].merge(params[:headers] || {})
  params[:headers]['Host'] ||= '' << params[:host_port]
  # if path is empty or doesn't start with '/', insert one
  unless params[:path][0, 1] == '/'
    params[:path].insert(0, '/')
  end
  if block_given?
    $stderr.puts("Excon requests with a block are deprecated, pass :response_block instead (#{caller.first})")
    params[:response_block] = Proc.new
  end
  if params.has_key?(:instrumentor)
    if (retries_remaining ||= params[:retry_limit]) < params[:retry_limit]
      event_name = "#{params[:instrumentor_name]}.retry"
    else
      event_name = "#{params[:instrumentor_name]}.request"
    end
    response = params[:instrumentor].instrument(event_name, params) do
      request_kernel(params)
    end
    params[:instrumentor].instrument("#{params[:instrumentor_name]}.response", response.attributes)
    response
  else
    request_kernel(params)
  end
rescue => request_error
  if params[:idempotent] && [Excon::Errors::Timeout, Excon::Errors::SocketError,
      Excon::Errors::HTTPStatusError].any? {|ex| request_error.kind_of? ex }
    retries_remaining ||= params[:retry_limit]
    retries_remaining -= 1
    if retries_remaining > 0
      if params[:body].respond_to?(:pos=)
        params[:body].pos = 0
      end
      retry
    else
      if params.has_key?(:instrumentor)
        params[:instrumentor].instrument("#{params[:instrumentor_name]}.error", :error => request_error)
      end
      raise(request_error)
    end
  else
    if params.has_key?(:instrumentor)
      params[:instrumentor].instrument("#{params[:instrumentor_name]}.error", :error => request_error)
    end
    raise(request_error)
  end
end