def METHOD_NAME(
    request: ApiRequest, available: Collection[str]
) -> Optional[str]:
    """
    Determine a MIME content type based on client and server capabilities
    Client preferences are determined both from the standard HTTP Accept
    header provided by the client, and by an optional `f` parameter which
    can override the Accept header.
    :param request: HTTP request with Accept header and/or f parameter
    :param available: List of MIME types that the server can produce
    :return: the MIME type that is most acceptable to both client and server,
             or None if there is no MIME type acceptable to both
    """
    if 'f' in request.query:  # overrides headers
        content_type = request.query['f'][0]
        return (
            content_type
            if available is None or content_type in available
            else None
        )
    accept = re.split(', *', request.headers.get('Accept'))
    def parse_part(part: str) -> tuple[float, str]:
        if ';q=' in part:
            subparts = part.split(';q=')
            return float(subparts[1]), subparts[0]
        else:
            return 1, part
    type_specs = sorted([parse_part(part) for part in accept], reverse=True)
    types = [ts[1] for ts in type_specs]
    for allowed_type in types:
        for available_type in available:
            # We (ab)use fnmatch to match * wildcards from accept headers
            if fnmatch.fnmatch(available_type, allowed_type):
                return available_type
    return None