def http_get(uri, retries_left = 10)
      raise RedirectError, 'Too many redirects' if retries_left.zero?

      case (response = Net::HTTP.get_response(URI(uri)))
      when Net::HTTPClientError
        nil
      when Net::HTTPServerError
        raise Net::HTTPServerException.new(response.message, response)
      when Net::HTTPFound, Net::HTTPPermanentRedirect
        http_get(response['location'], retries_left - 1)
      else
        StringIO.new(response.body)
      end
    end
def http_get(uri, retries_left = 10)
      raise RedirectError, 'Too many redirects' if retries_left.zero?

      case (response = Net::HTTP.get_response(URI(uri)))
      when Net::HTTPClientError
        nil
      when Net::HTTPServerError
        raise Net::HTTPServerException.new(response.message, response)
      when Net::HTTPFound, Net::HTTPPermanentRedirect
        http_get(response['location'], retries_left - 1)
      else
        StringIO.new(response.body)
      end
    end
Wrapper for a Net::HTTP GET request that handles redirects.

 :nocov: