parse static method

AuthorizationHeader parse(
  1. String value
)

Parses and creates the appropriate AuthorizationHeader subclass based on the provided authorization string from HTTP headers.

This method checks the header's prefix to determine whether it's a Bearer or Basic authorization type and returns the corresponding header object.

Throws a FormatException if the header value is invalid or unrecognized.

Implementation

static AuthorizationHeader parse(final String value) {
  if (value.isEmpty) {
    throw const FormatException('Value cannot be empty');
  }

  if (value.startsWith(BearerAuthorizationHeader.prefix.trim())) {
    return BearerAuthorizationHeader.parse(value);
  } else if (value.startsWith(BasicAuthorizationHeader.prefix.trim())) {
    return BasicAuthorizationHeader.parse(value);
  } else if (value.startsWith(DigestAuthorizationHeader.prefix.trim())) {
    return DigestAuthorizationHeader.parse(value);
  }

  throw const FormatException('Invalid header format');
}