# File lib/excon/connection.rb, line 19
    def initialize(url, params = {})
      uri = URI.parse(url)
      @connection = Excon.defaults.merge({
        :host              => uri.host,
        :path              => uri.path,
        :port              => uri.port.to_s,
        :query             => uri.query,
        :scheme            => uri.scheme,
      }).merge!(params)
      # merge does not deep-dup, so make sure headers is not the original
      @connection[:headers] = @connection[:headers].dup

      @proxy = nil

      # 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

      # Use Basic Auth if url contains a login
      if uri.user || uri.password
        auth = ["#{uri.user}:#{uri.password}"].pack('m').delete("\r\n")
        @connection[:headers]['Authorization'] ||= "Basic #{auth}"
      end

      @socket_key = '' << @connection[:host] << ':' << @connection[:port]
      reset
    end