isAllowed method

bool isAllowed(
  1. String path,
  2. String userAgent
)

Checks if a path is allowed for a user agent

Implementation

bool isAllowed(String path, String userAgent) {
  // Normalize the path
  if (!path.startsWith('/')) {
    path = '/$path';
  }

  // Check if there are rules for this user agent
  final userAgentLower = userAgent.toLowerCase();
  final specificRules = _findSpecificUserAgent(userAgentLower);
  final wildcardRules = _disallowedPaths['*'] ?? [];

  // If no rules for this user agent or wildcard, assume allowed
  if (specificRules == null && wildcardRules.isEmpty) {
    return true;
  }

  // Check specific rules first
  if (specificRules != null) {
    // Check allowed paths first (they take precedence)
    final allowedPaths = _allowedPaths[specificRules] ?? [];
    for (final allowedPath in allowedPaths) {
      if (_pathMatches(path, allowedPath)) {
        return true;
      }
    }

    // Check disallowed paths
    final disallowedPaths = _disallowedPaths[specificRules] ?? [];
    for (final disallowedPath in disallowedPaths) {
      if (_pathMatches(path, disallowedPath)) {
        return false;
      }
    }
  }

  // Check wildcard rules if no specific rules matched
  // Check allowed paths first (they take precedence)
  final wildcardAllowedPaths = _allowedPaths['*'] ?? [];
  for (final allowedPath in wildcardAllowedPaths) {
    if (_pathMatches(path, allowedPath)) {
      return true;
    }
  }

  // Check disallowed paths
  for (final disallowedPath in wildcardRules) {
    if (_pathMatches(path, disallowedPath)) {
      return false;
    }
  }

  // If no rules matched, assume allowed
  return true;
}