Function aws_sdk_rust::http::client::proxy::proxy_unless_domain_exempted
[−]
[src]
pub fn proxy_unless_domain_exempted(for_domain: Option<&Url>) -> Result<Option<Proxy>>
Returns a Proxy
from either the http_proxy
or https_proxy
environment variable if
either is set and the given domain name is not matched in the no_proxy
environment variable
domain extension set.
See the http_proxy()
and https_proxy()
functions for more details about the
http_proxy
and https_proxy
environment variable parsing. This function honors the
no_proxy
environment variable which is assumed to be a comma separated set of domain
extensions. If the given domain matches one of these extensions then no proxy information
should be returned (i.e. a return of Ok(None)
).
Errors
- If either the
http_proxy()
orhttps_proxy()
was unsuccessful
Examples
Behavior when domain matches extension set for http_proxy:
extern crate habitat_http_client; extern crate url; use std::str::FromStr; use url::Url; use habitat_http_client::proxy; fn main() { std::env::set_var("http_proxy", "http://proxy.example.com:8001/"); std::env::set_var("no_proxy", "localhost,127.0.0.1,localaddress,.localdomain.com"); let for_domain = Url::from_str("http://server.localdomain.com").unwrap(); let info = proxy::proxy_unless_domain_exempted(Some(&for_domain)).unwrap(); assert!(info.is_none()); }
Behavior when domain matches extension set for https_proxy:
extern crate habitat_http_client; extern crate url; use std::str::FromStr; use url::Url; use habitat_http_client::proxy; fn main() { std::env::set_var("https_proxy", "http://proxy.example.com:8001/"); std::env::set_var("no_proxy", "localhost,127.0.0.1,localaddress,.localdomain.com"); let for_domain = Url::from_str("https://server.localdomain.com").unwrap(); let info = proxy::proxy_unless_domain_exempted(Some(&for_domain)).unwrap(); assert!(info.is_none()); }
Behavior when both lower case and uppercase environment variables are set:
extern crate habitat_http_client; extern crate url; use std::str::FromStr; use url::Url; use habitat_http_client::proxy; fn main() { std::env::set_var("https_proxy", "http://lower.example.com"); std::env::set_var("HTTPS_PROXY", "http://upper.example.com"); std::env::set_var("no_proxy", ".lower,localdomain.com"); std::env::set_var("NO_PROXY", ".upper.localdomain.com"); let for_domain = Url::from_str("https://server.lower.localdomain.com").unwrap(); let info = proxy::proxy_unless_domain_exempted(Some(&for_domain)).unwrap(); assert!(info.is_none()); }
Behavior when domain does not match extension set:
extern crate habitat_http_client; extern crate url; use std::str::FromStr; use url::Url; use habitat_http_client::proxy; fn main() { std::env::set_var("https_proxy", "http://itsme:asecret@proxy.example.com:8001/"); std::env::set_var("no_proxy", "localhost,127.0.0.1,localaddress,.localdomain.com"); let for_domain = Url::from_str("https://www.example.com").unwrap(); let info = proxy::proxy_unless_domain_exempted(Some(&for_domain)).unwrap().unwrap(); assert_eq!(info.scheme(), "http"); assert_eq!(info.host(), "proxy.example.com"); assert_eq!(info.port(), 8001); assert_eq!(info.authorization_header_value().unwrap(), "Basic aXRzbWU6YXNlY3JldA=="); }