/// Builds a new hyper HTTP client with appropriate SSL configuration and HTTP/HTTPS proxy support.
///
/// ## Linux Platforms
///
/// We need a set of root certificates when connected to SSL/TLS web endpoints and this usually
/// boiled down to using an all-in-one certificate file (such as a `cacert.pem` file) or a directory
/// of files which are certificates. The strategy to location or use a reasonable set of
/// certificates is as follows:
///
/// 1. If the `SSL_CERT_FILE` environment variable is set, then use its value for the certificates.
///    Internally this is triggering default OpenSSL behavior for this environment variable.
/// 2. If the `SSL_CERT_DIR` environment variable is set, then use its value for the directory
///    containing certificates. Like the `SSL_CERT_FILE` case above, this triggers default OpenSSL
///    behavior for this environment variable.
/// 3. If the `core/cacerts` Habitat package is installed locally, then use the latest release's
///    `cacert.pem` file.
/// 4. If none of the conditions above are met, then a `cacert.pem` will be written in an SSL cache
///    directory (by default `/hab/cache/ssl` for a root user and `$HOME/.hab/cache/ssl` for a
///    non-root user) and this will be used. The contents of this file will be inlined in this
///    crate at build time as a fallback insurance policy, meaning that if the a program using this
///    code is operating in a minimal environment which may not contain system certificates, it can
///    still operate. Once a `core/cacerts` Habitat package is present, the logic would fall back
///    to preferring the package version to the cached/inline file version.
///
/// ## Mac Platforms
///
/// The Mac platform uses a Security Framework to store and find root certificates and the hyper
/// library will default to using this on the Mac. Therefore the behavior on the Mac remains
/// unchanged and will use the system's certificates.
Builds a new hyper HTTP client with appropriate SSL configuration and HTTP/HTTPS proxy support.
Builds a new hyper HTTP client with appropriate SSL configuration and HTTP / HTTPS proxy support .
fn new_hyper_client(url: &Url, fs_root_path: Option<&Path>) -> Result<HyperClient> {
    let connector = ssl_connector(fs_root_path)?;
    let ssl_client = OpensslClient::from(connector);
    let timeout_in_secs = match env::var("HAB_CLIENT_SOCKET_TIMEOUT") {
        Ok(t) => {
            match t.parse::<u64>() {
                Ok(n) => n,
                Err(_) => CLIENT_SOCKET_RW_TIMEOUT_SEC,
            }
        }
        Err(_) => CLIENT_SOCKET_RW_TIMEOUT_SEC,
    };
    debug!("Client socket timeout: {} secs", timeout_in_secs);
    let timeout = Some(Duration::from_secs(timeout_in_secs));
    match proxy_unless_domain_exempted(Some(url))? {
        Some(proxy) => {
            debug!("Using proxy {}:{}...", proxy.host(), proxy.port());
            let connector = ProxyHttpsConnector::new(proxy, ssl_client)?;
            let pool = Pool::with_connector(Config::default(), connector);
            let mut client = HyperClient::with_protocol(Http11Protocol::with_connector(pool));
            client.set_read_timeout(timeout);
            client.set_write_timeout(timeout);
            Ok(client)
        }
        None => {
            let connector = HttpsConnector::new(ssl_client);
            let pool = Pool::with_connector(Config::default(), connector);
            let mut client = HyperClient::with_protocol(Http11Protocol::with_connector(pool));
            client.set_read_timeout(timeout);
            client.set_write_timeout(timeout);
            Ok(client)
        }
    }
}
fn new_hyper_client ( url : & Url , fs_root_path : Option < & Path > ) -> Result < HyperClient > { let connector = ssl_connector ( fs_root_path ) ? ; let ssl_client = OpensslClient :: from ( connector ) ; let timeout_in_secs = match env :: var ( " " ) { Ok ( t ) => { match t . parse :: < u64 > ( ) { Ok ( n ) => n , Err ( _ ) => CLIENT_SOCKET_RW_TIMEOUT_SEC , } } Err ( _ ) => CLIENT_SOCKET_RW_TIMEOUT_SEC , } ; debug ! ( " " timeout_in_secs ) ; let timeout = Some ( Duration :: from_secs ( timeout_in_secs ) ) ; match proxy_unless_domain_exempted ( Some ( url ) ) ? { Some ( proxy ) => { debug ! ( " " proxy host ( ) proxy port ( ) ) ; let connector = ProxyHttpsConnector :: new ( proxy , ssl_client ) ? ; let pool = Pool :: with_connector ( Config :: default ( ) , connector ) ; let mut client = HyperClient :: with_protocol ( Http11Protocol :: with_connector ( pool ) ) ; client . set_read_timeout ( timeout ) ; client . set_write_timeout ( timeout ) ; Ok ( client ) } None => { let connector = HttpsConnector :: new ( ssl_client ) ; let pool = Pool :: with_connector ( Config :: default ( ) , connector ) ; let mut client = HyperClient :: with_protocol ( Http11Protocol :: with_connector ( pool ) ) ; client . set_read_timeout ( timeout ) ; client . set_write_timeout ( timeout ) ; Ok ( client ) } } }
Builds a new hyper HTTP client with appropriate SSL configuration and HTTP/HTTPS proxy support.
Builds a new hyper HTTP client with appropriate SSL configuration and HTTP / HTTPS proxy support .
url
&Url
fs_root_path
Option<&Path>
linux platforms
We need a set of root certificates when connected to SSL/TLS web endpoints and this usually
boiled down to using an all-in-one certificate file (such as a `cacert.pem` file) or a directory
of files which are certificates. The strategy to location or use a reasonable set of
certificates is as follows.

1. If the `SSL_CERT_FILE` environment variable is set, then use its value for the certificates.
Internally this is triggering default OpenSSL behavior for this environment variable.
2. If the `SSL_CERT_DIR` environment variable is set, then use its value for the directory
containing certificates. Like the `SSL_CERT_FILE` case above, this triggers default OpenSSL
behavior for this environment variable.
3. If the `core/cacerts` Habitat package is installed locally, then use the latest release's
`cacert.pem` file.
4. If none of the conditions above are met, then a `cacert.pem` will be written in an SSL cache
directory (by default `/hab/cache/ssl` for a root user and `$HOME/.hab/cache/ssl` for a
non-root user) and this will be used. The contents of this file will be inlined in this
crate at build time as a fallback insurance policy, meaning that if the a program using this
code is operating in a minimal environment which may not contain system certificates, it can
still operate. Once a `core/cacerts` Habitat package is present, the logic would fall back
to preferring the package version to the cached/inline file version.
We need a set of root certificates when connected to SSL / TLS web endpoints and this usually boiled down to using an all - in - one certificate file ( such as a ` cacert . pem ` file ) or a directory of files which are certificates . The strategy to location or use a reasonable set of certificates is as follows . 1 . If the ` SSL_CERT_FILE ` environment variable is set then use its value for the certificates . Internally this is triggering default OpenSSL behavior for this environment variable . 2 . If the ` SSL_CERT_DIR ` environment variable is set then use its value for the directory containing certificates . Like the ` SSL_CERT_FILE ` case above this triggers default OpenSSL behavior for this environment variable . 3 . If the ` core / cacerts ` Habitat package is installed locally then use the latest release ' s ` cacert . pem ` file . 4 . If none of the conditions above are met then a ` cacert . pem ` will be written in an SSL cache directory ( by default ` / hab / cache / ssl ` for a root user and ` $HOME / . hab / cache / ssl ` for a non - root user ) and this will be used . The contents of this file will be inlined in this crate at build time as a fallback insurance policy meaning that if the a program using this code is operating in a minimal environment which may not contain system certificates it can still operate . Once a ` core / cacerts ` Habitat package is present the logic would fall back to preferring the package version to the cached / inline file version .
mac platforms
The Mac platform uses a Security Framework to store and find root certificates and the hyper
library will default to using this on the Mac. Therefore the behavior on the Mac remains
unchanged and will use the system's certificates.
The Mac platform uses a Security Framework to store and find root certificates and the hyper library will default to using this on the Mac . Therefore the behavior on the Mac remains unchanged and will use the system ' s certificates .