decodeMcpHeaderValue function

String? decodeMcpHeaderValue(
  1. String header
)

The value a header carries (sentinel decoded), or null when the header value has characters a header may not hold or a malformed sentinel.

Implementation

String? decodeMcpHeaderValue(String header) {
  if (header.codeUnits.any((c) => (c < 0x20 && c != 0x09) || c > 0x7e)) return null;
  if (header.startsWith('=?base64?') && header.endsWith('?=') && header.length >= 11) {
    try {
      return utf8.decode(base64.decode(header.substring(9, header.length - 2)));
    } on FormatException {
      return null;
    }
  }
  return header;
}