EnvironmentProxyConfig.fromEnvironment constructor
Reads the variables from environment (usually
Platform.environment).
Following curl, upper-case HTTP_PROXY is ignored (it can be injected
by CGI servers through the Proxy: request header); http_proxy must
be lower case. The other variables may be either case.
Implementation
factory EnvironmentProxyConfig.fromEnvironment(
Map<String, String> environment,
) {
String? read(String name, {bool allowUpper = true}) {
final lower = environment[name];
if (lower != null && lower.trim().isNotEmpty) return lower.trim();
if (!allowUpper) return null;
final upper = environment[name.toUpperCase()];
if (upper != null && upper.trim().isNotEmpty) return upper.trim();
return null;
}
ProxyEntry? entry(String? value) =>
value == null ? null : ProxyListParser.parseProxyUrl(value);
return EnvironmentProxyConfig(
httpProxy: entry(read('http_proxy', allowUpper: false)),
httpsProxy: entry(read('https_proxy')),
allProxy: entry(read('all_proxy')),
noProxy: ProxyBypassRules.parse(read('no_proxy')),
);
}