def METHOD_NAME(generator, format, name, encoding=None, user_agent=None): #TODO: Add support for 3rd party (e.g. nginx file serving)
  """
  @param data An iterator of rows, where every row is a list of strings
  @param format Either "csv" or "xls"
  @param name Base name for output file
  @param encoding Unicode encoding for data
  """
  content_type = FORMAT_TO_CONTENT_TYPE.get(format, 'application/octet-stream')
  if format == 'csv':
    resp = StreamingHttpResponse(generator, content_type=content_type)
    try:
      del resp['Content-Length']
    except KeyError:
      pass
  elif format == 'xls':
    format = 'xlsx'
    resp = HttpResponse(next(generator), content_type=content_type)
  elif format == 'json' or format == 'txt':
    resp = HttpResponse(generator, content_type=content_type)
  else:
    raise Exception("Unknown format: %s" % format)
  try:
    name = name.encode('ascii')
    format = format.encode('ascii')
    resp['Content-Disposition'] = b'attachment; filename="%s.%s"' % (name, format)
  except UnicodeEncodeError:
    name = quote(name)
    if user_agent is not None and 'Firefox' in user_agent:
      # Preserving non-ASCII filename. See RFC https://tools.ietf.org/html/rfc6266#appendix-D, only FF works
      resp['Content-Disposition'] = 'attachment; filename*="%s.%s"' % (name, format)
    else:
      resp['Content-Disposition'] = 'attachment; filename="%s.%s"' % (name, format)
  return resp