isInsecureConnectionAllowed function Null safety
- 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.
Implementation
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 = host.host;
} else {
throw ArgumentError.value(
host, "host", "Must be a String or InternetAddress");
}
final topMatchedPolicy = _findBestDomainNetworkPolicy(hostString);
final envOverride = bool.fromEnvironment(
"dart.library.io.may_insecurely_connect_to_all_domains",
defaultValue: true);
return topMatchedPolicy?.allowInsecureConnections ??
(envOverride && _EmbedderConfig._mayInsecurelyConnectToAllDomains);
}