hasType method

bool hasType(
  1. String primaryType,
  2. String subType0, [
  3. String? orSubType1,
  4. String? orSubType2,
  5. String? orSubType3,
  6. String? orSubType4,
])

Checks if "content-type" equals with primaryType and one of sub types.

To check exact content type: hasType('application', 'json')

Multiple sub type choices: hasType('application', 'json', 'geo+json')

This checks only primary type and sub type components of "content-type" header values.

Implementation

bool hasType(
  String primaryType,
  String subType0, [
  String? orSubType1,
  String? orSubType2,
  String? orSubType3,
  String? orSubType4,
]) {
  if (mediaType.type == primaryType) {
    final sub = mediaType.subtype;
    if (sub == subType0) return true;
    if (orSubType1 != null) {
      if (sub == orSubType1) return true;
      if (orSubType2 != null) {
        if (sub == orSubType2) return true;
        if (orSubType3 != null) {
          if (sub == orSubType3) return true;
          if (orSubType4 != null) {
            if (sub == orSubType4) return true;
          }
        }
      }
    }
  }

  return false;
}