class Excon::Connection

def connect

def connect
  new_socket = open_socket
  if https?
    # create ssl context
    ssl_context = OpenSSL::SSL::SSLContext.new
    if Excon.ssl_verify_peer
      # turn verification on
      ssl_context.verify_mode = OpenSSL::SSL::VERIFY_PEER
      if Excon.ssl_ca_path
        ssl_context.ca_path = Excon.ssl_ca_path
      else
        # use default cert store
        store = OpenSSL::X509::Store.new
        store.set_default_paths
        ssl_context.cert_store = store
      end
    else
      # turn verification off
      ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end
    if @connection.has_key?(:client_cert) && @connection.has_key?(:client_key)
      ssl_context.cert = OpenSSL::X509::Certificate.new(File.read(@connection[:client_cert]))
      ssl_context.key = OpenSSL::PKey::RSA.new(File.read(@connection[:client_key]))
    end
    new_socket = open_ssl_socket(new_socket, ssl_context)
  end
  new_socket
end