assignCodec method
Register a new codec for a basic codecMediaType.
The codecMediaType should be a basic MIME-Type, consisting of a
primary type (like text or application) and a basic subtype (like
plain orjson). Anything before a + (as in application/td+json)
in a subtype as well as parameters (like charset=utf-8) are ignored when
assigning the codec.
Therefore, a codec assigned to application/foo+bar;charset=utf-8 would
be applied to all Content-Types that are derived from application/bar
(like application/baz+bar, for example).
If the codecMediaType cannot be parsed, an ArgumentError is thrown.
Implementation
void assignCodec(
String codecMediaType,
ContentCodec codec,
) {
final parsedMediaType = CodecMediaType.parse(codecMediaType);
if (parsedMediaType == null) {
throw ArgumentError.value(
codecMediaType,
"codecMediaType",
"Incorrect format",
);
}
_codecs[parsedMediaType] = codec;
}