Function aws_sdk_rust::http::client::proxy::http_proxy [] [src]

pub fn http_proxy() -> Result<Option<Proxy>>

Returns a Proxy from the http_proxy environment variable, if it is set.

The value of http_proxy must be a parseable URL such as http://proxy.company.com:8001/ otherwise a parsing error will be returned. If the port is not present, than the default port numbers of http/80 and https/443 will be returned. If the http_proxy environment variable is not set or is empty, then a Result of None will be returned.

References:

Examples

Behavior when environment variable is set:

use std;
use habitat_http_client::proxy;

std::env::set_var("http_proxy", "http://proxy.example.com:8001/");
let info = proxy::http_proxy().unwrap().unwrap();

assert_eq!(info.scheme(), "http");
assert_eq!(info.host(), "proxy.example.com");
assert_eq!(info.port(), 8001);
assert!(info.authorization_header_value().is_none());

Behavior when environment variable is set with basic auth credentials:

use std;
use habitat_http_client::proxy;

std::env::set_var("http_proxy", "http://itsme:asecret@proxy.example.com");
let info = proxy::http_proxy().unwrap().unwrap();

assert_eq!(info.scheme(), "http");
assert_eq!(info.host(), "proxy.example.com");
assert_eq!(info.port(), 80);
assert_eq!(info.authorization_header_value().unwrap(), "Basic aXRzbWU6YXNlY3JldA==");

Behavior when both lower case and upper case environment variables are set:

use std;
use habitat_http_client::proxy;

std::env::set_var("http_proxy", "http://lower.example.com");
std::env::set_var("HTTP_PROXY", "http://upper.example.com");
let info = proxy::http_proxy().unwrap().unwrap();

assert_eq!(info.host(), "lower.example.com");

Behavior when environment variable is empty:

use std;
use habitat_http_client::proxy;

std::env::set_var("http_proxy", "");

assert!(proxy::http_proxy().unwrap().is_none());

Errors

  • If the value of the http_proxy environment variable cannot be parsed as a URL
  • If the URL scheme is not a valid type (currently only supported schemes are http and https)
  • If the URL is missing a host/domain segement
  • If the URL is missing a port number and a default cannot be determined