isInsecureConnectionAllowed function Null safety

bool isInsecureConnectionAllowed(
  1. dynamic host

Whether insecure connections to host are allowed.

host must be a String or InternetAddress.

If any of the domain policies match host, the matching policy will make the decision. If multiple policies apply, the top matching policy makes the decision. If none of the domain policies match, the embedder default is used.

Loopback addresses are always allowed.


bool isInsecureConnectionAllowed(dynamic host) {
  String hostString;
  if (host is String) {
    try {
      if ("localhost" == host || InternetAddress(host).isLoopback) return true;
    } on ArgumentError {
      // Assume not loopback.
    hostString = host;
  } else if (host is InternetAddress) {
    if (host.isLoopback) return true;
    hostString =;
  } else {
    throw ArgumentError.value(
        host, "host", "Must be a String or InternetAddress");
  final topMatchedPolicy = _findBestDomainNetworkPolicy(hostString);
  final envOverride = bool.fromEnvironment(
      defaultValue: true);
  return topMatchedPolicy?.allowInsecureConnections ??
      (envOverride && _EmbedderConfig._mayInsecurelyConnectToAllDomains);