class Selenium::WebDriver::Remote::Http::Default

def request(verb, url, headers, payload, redirects = 0)

def request(verb, url, headers, payload, redirects = 0)
  retries = 0
  begin
    request = new_request_for(verb, url, headers, payload)
    response = response_for(request)
  rescue Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EADDRINUSE, Errno::EADDRNOTAVAIL
    # a retry is sometimes needed:
    #   on Windows XP where we may quickly run out of ephemeral ports
    #   when the port becomes temporarily unavailable
    #
    # A more robust solution is bumping the MaxUserPort setting
    # as described here:
    #
    # http://msdn.microsoft.com/en-us/library/aa560610%28v=bts.20%29.aspx
    raise if retries >= MAX_RETRIES
    retries += 1
    sleep 2
    retry
  rescue Errno::ECONNREFUSED => e
    raise e.class, "using proxy: #{proxy.http}" if use_proxy?
    raise
  end
  if response.is_a? Net::HTTPRedirection
    WebDriver.logger.debug("Redirect to #{response['Location']}; times: #{redirects}")
    raise Error::WebDriverError, 'too many redirects' if redirects >= MAX_REDIRECTS
    request(:get, URI.parse(response['Location']), DEFAULT_HEADERS.dup, nil, redirects + 1)
  else
    WebDriver.logger.debug("   <<<  #{response.instance_variable_get(:@header).inspect}", id: :header)
    create_response response.code, response.body, response.content_type
  end
end