parseHeaders function

Map<String, String> parseHeaders(
  1. List<String> headerStrings
)

Parse header strings of the form "Key: Value" into a map.

Implementation

Map<String, String> parseHeaders(List<String> headerStrings) {
  final headers = <String, String>{};
  for (final h in headerStrings) {
    final colonIdx = h.indexOf(':');
    if (colonIdx == -1) continue;
    final key = h.substring(0, colonIdx).trim();
    final value = h.substring(colonIdx + 1).trim();
    if (key.isNotEmpty) {
      headers[key] = value;
    }
  }
  return headers;
}