isValidHeaderName method

bool isValidHeaderName(
  1. String name
)

Header-name validation for transport-level metadata.

Enforces basic safety invariants:

  • non-empty
  • no control characters
  • no CR/LF/NUL (prevents header injection via log/HTTP bridging)

Implementation

bool isValidHeaderName(String name) {
  if (name.isEmpty || name.length > maxHeaderNameBytes) return false;
  for (final unit in name.codeUnits) {
    if (unit <= 0x20 || unit == 0x7F) return false;
    if (unit == 0x0D || unit == 0x0A || unit == 0x00) return false;
  }
  return true;
}