decodeBaggage static method
Parses a W3C baggage header value.
Entries that are not key=value are skipped rather than throwing — this
runs on input from another service, and one malformed entry must not
fail the request.
Implementation
static Map<String, String> decodeBaggage(String? header) {
if (header == null || header.trim().isEmpty) {
return {};
}
final result = <String, String>{};
for (final entry in header.split(',')) {
final index = entry.indexOf('=');
if (index <= 0) {
continue;
}
final key = Uri.decodeQueryComponent(entry.substring(0, index).trim());
final value = Uri.decodeQueryComponent(entry.substring(index + 1).trim());
if (key.isNotEmpty) {
result[key] = value;
}
}
return result;
}