Codec codecForContentType(ContentType contentType)

Returns a Codec for contentType.

See add.

Source

Codec codecForContentType(ContentType contentType) {
  Codec contentCodec;
  Codec charsetCodec;

  var subtypes = _fullySpecificedCodecs[contentType.primaryType];
  if (subtypes != null) {
    contentCodec = subtypes[contentType.subType];
  }

  if (contentCodec == null) {
    contentCodec = _primaryTypeCodecs[contentType.primaryType];
  }

  if ((contentType?.charset?.length ?? 0) > 0) {
    charsetCodec = _codecForCharset(contentType.charset);
  } else if (contentType.primaryType == "text" && contentCodec == null) {
    charsetCodec = LATIN1;
  } else {
    charsetCodec = _defaultCharsetCodecForType(contentType);
  }

  if (contentCodec != null) {
    if (charsetCodec != null) {
      return contentCodec.fuse(charsetCodec);
    }
    return contentCodec;
  }

  if (charsetCodec != null) {
    return charsetCodec;
  }

  return null;
}