from static method
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();
// Handle parameters (e.g. application/json; charset=utf-8) by taking only the first part
final baseType = lower.split(';').first.trim();
if (baseType == 'application/json') return json;
if (baseType == 'application/x-www-form-urlencoded') {
return formUrlEncoded;
}
if (baseType == 'multipart/form-data') return multipart;
if (baseType.startsWith('text/')) return text;
if (baseType == 'application/octet-stream') return binary;
return unknown;
}