isJsonMimeType static method

bool isJsonMimeType(
  1. String? contentType
)

Implementation

static bool isJsonMimeType(String? contentType) {
  if (contentType == null) {
    return false;
  }
  try {
    final mediaType = MediaType.parse(contentType);
    return mediaType.mimeType == 'application/json' ||
        mediaType.mimeType == 'text/json' ||
        mediaType.subtype.endsWith('+json');
  } catch (e, s) {
    warningLog(
      'Failed to parse the media type: $contentType, '
      'thus it is not a JSON MIME type.',
      s,
    );
    return false;
  }
}