parseHeaderList static method

List<String> parseHeaderList(
  1. Object? value,
  2. List<String> def
)

Parses a header list value, accepting a List or a comma separated String. Returns def for a null value, and an empty list for an explicitly empty value.

Implementation

static List<String> parseHeaderList(Object? value, List<String> def) {
  if (value == null) return def;

  if (value is Iterable) {
    return value
        .map((e) => e.toString().trim())
        .where((e) => e.isNotEmpty)
        .toList();
  }

  return value
      .toString()
      .split(',')
      .map((e) => e.trim())
      .where((e) => e.isNotEmpty)
      .toList();
}