Function env_proxy::for_url [] [src]

pub fn for_url(url: &Url) -> ProxyUrl

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, where the two rightmost columns are headed by two no_proxy components, the leftmost column contains hostnames, and the symbol inside each cell represents the result of checking the hostname against the corresponding component:

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 definitions stops.

The return value, if not None, is an opaque structure wrapping the raw value of the chosen environment variable.

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