class Bundler::Fetcher::Downloader

def fetch(uri, options = {}, counter = 0)

def fetch(uri, options = {}, counter = 0)
  raise HTTPError, "Too many redirects" if counter >= redirect_limit
  response = request(uri, options)
  Bundler.ui.debug("HTTP #{response.code} #{response.message} #{uri}")
  case response
  when Net::HTTPSuccess, Net::HTTPNotModified
    response
  when Net::HTTPRedirection
    new_uri = URI.parse(response["location"])
    if new_uri.host == uri.host
      new_uri.user = uri.user
      new_uri.password = uri.password
    end
    fetch(new_uri, options, counter + 1)
  when Net::HTTPRequestEntityTooLarge
    raise FallbackError, response.body
  when Net::HTTPUnauthorized
    raise AuthenticationRequiredError, uri.host
  when Net::HTTPNotFound
    raise FallbackError, "Net::HTTPNotFound"
  else
    raise HTTPError, "#{response.class}#{": #{response.body}" unless response.body.empty?}"
  end
end