Function env_proxy::for_url [] [src]

pub fn for_url(url: &Url) -> Option<(String, u16)>

Determine proxy parameters for a URL by examining the environment variables.

Attention: in a multithreaded program, care should be taken not to change the environment in multiple threads simultaneously without some form of serialization.

Most environment variables described here can be defined either with an all-lowercase or an all-uppercase name. If both versions are defined, the all-lowercase name takes precedence (e.g., no_proxy will be used even if NO_PROXY is defined.) The only exception is http_proxy, where only the lowercase name is checked for. This text will use the lowercase variants for simplicity.

If no_proxy is defined, check the host part of the URL against its components and return None if there is any match. The value of no_proxy should be a space- or comma-separated list of host/domain names or IP addresses for which no proxying should be done, or a single ' * ' (asterisk) which means that proxying is disabled for all hosts. Empty names are skipped. Names beginning with a dot are not treated specially; matching is always done by full domain name component. A name consisting of a bare dot is skipped (this is different from curl's behavior.) The rules are summarized in the following table:

example.org .example.org
example.org
a.example.org
xample.org
org

For the ftp protocol scheme, ftp_proxy is checked first; for https, https_proxy is checked. Both schemes will fall back to http_proxy, then all_proxy if the former is undefined. For http, http_proxy is cheked first, then all_proxy. For all other schemes only all_proxy is checked. In this context, "checked" means that the value of a variable is used if present, and the search for further definition stops.

The return value, if not None, is a tuple consisting of the proxy hostname and the port, which are obtained from the chosen environment variable parsed as a URL.

If the target URL matches no_proxy, or if the hostname cannot be extracted from the URL, the function returns None. If the port is not explicitly defined in the proxy URL, the value 8080 is used, which corresponds to http-alt in the IANA port registry. This is different from curl, which uses port 1080 as the default.