Skip to main content

subspace_core/path/
network.rs

1//! The network variables a child process such as the Azure CLI gets: proxy
2//! settings and certificate bundles.
3
4/// Proxy variables, upper and lower case, as curl, Python and Go read them.
5pub const PROXY_VARIABLES: [&str; 8] = [
6    "HTTPS_PROXY",
7    "https_proxy",
8    "HTTP_PROXY",
9    "http_proxy",
10    "ALL_PROXY",
11    "all_proxy",
12    "NO_PROXY",
13    "no_proxy",
14];
15
16/// Certificate bundle variables that Python `requests` and OpenSSL read.
17pub const CERTIFICATE_VARIABLES: [&str; 3] =
18    ["REQUESTS_CA_BUNDLE", "SSL_CERT_FILE", "SSL_CERT_DIR"];
19
20/// Whether `name` is one of the network variables, exactly as written.
21pub fn is_network_variable(name: &str) -> bool {
22    PROXY_VARIABLES.contains(&name) || CERTIFICATE_VARIABLES.contains(&name)
23}
24
25#[cfg(test)]
26mod tests {
27    use super::is_network_variable;
28
29    #[test]
30    fn network_variables_match_exactly_as_written() {
31        assert!(is_network_variable("HTTPS_PROXY"));
32        assert!(is_network_variable("no_proxy"));
33        assert!(is_network_variable("SSL_CERT_FILE"));
34        assert!(!is_network_variable("Https_Proxy"));
35        assert!(!is_network_variable("PATH"));
36    }
37}