from static method

ContentType from(
  1. String? mimeType
)

parses the ContentType from a MIME type string.

Returns ContentType.unknown if the mime type is null or not recognized.

Implementation

static ContentType from(String? mimeType) {
  if (mimeType == null) return unknown;

  final lower = mimeType.toLowerCase();

  if (lower.contains('application/json')) return json;
  if (lower.contains('application/x-www-form-urlencoded')) {
    return formUrlEncoded;
  }
  if (lower.contains('multipart/form-data')) return multipart;
  if (lower.contains('text/')) return text;
  if (lower.contains('application/octet-stream')) return binary;

  return unknown;
}