acceptsContentType method

bool acceptsContentType(
  1. ContentType contentType
)

Whether a Response may contain a body of type contentType.

This method searches acceptableContentTypes for a match with contentType. If one exists, this method returns true. Otherwise, it returns false.

Note that if no Accept header is present, this method always returns true.

Implementation

bool acceptsContentType(ContentType contentType) {
  if (acceptableContentTypes!.isEmpty) {
    return true;
  }

  return acceptableContentTypes!.any((acceptable) {
    if (acceptable.primaryType == "*") {
      return true;
    }

    if (acceptable.primaryType == contentType.primaryType) {
      if (acceptable.subType == "*") {
        return true;
      }

      if (acceptable.subType == contentType.subType) {
        return true;
      }
    }

    return false;
  });
}