# File lib/rubygems/commands/test_command.rb, line 214
  def upload_results(yaml, results_url=nil)
    begin
      results_url ||= config["upload_service_url"] || 'http://test.rubygems.org/test_results' 
      url = URI.parse(results_url)

      net_http_args = [url.host, url.port]

      if proxy_uri = proxy
        net_http_args += [
          proxy_uri.host,
          proxy_uri.port,
          proxy_uri.user,
          proxy_uri.password
        ]
      end

      http = Net::HTTP.new(*net_http_args)

      if ENV["RG_T_DEBUG_HTTP"]
        http.set_debug_output($stderr)
      end

      req = Net::HTTP::Post.new(url.path)
      req.set_form_data({:results => yaml})
      response = http.start { |x| x.request(req) }

      case response
      when Net::HTTPSuccess
        body = YAML::load(response.body)
        if body[:success]
          url = body[:data][0] if body[:data]
          say "\nTest results posted successfully! \n\nresults url:\t#{url}\n\n"
        else
          body[:errors].each do |error|
            say error
          end if body[:errors]
        end
      when Net::HTTPRedirection
        location = response.fetch('Location')
        if !location or URI.parse(location) == url
          say %[Caught redirection but was unable to redirect to #{location}.]
        else
          upload_results yaml, location 
        end
      when Net::HTTPNotFound
        say %q[Unable to find where to put the test results. Try: `gem update rubygems-test`]
      when Net::HTTPClientError
        say %q[Results server didn't like the results submission. Try: `gem update rubygems-test`]
      when Net::HTTPServerError
        say %q[Oof. Something went wrong on the results server processing these results. Sorry!]
      else
        say %q[Something weird happened. Probably a bug.]
      end
    rescue Errno::ECONNREFUSED => e
      say 'Unable to post test results. Can\'t connect to the results server.'
    rescue => e
      say e.message
      say e.backtrace
    end
  end