JFLib

netio/proxy.rs#

Source: lib/netio/proxy.rs

proxy -- which HTTP proxy a request goes through (Client::with_proxy)

  Proxy::new("http://user:pw@proxy.lan:3128")   one proxy for http and https
  Proxy::none().http(..).https(..)               a proxy per scheme (Endpoint::parse)
  proxy.no_proxy("localhost, .corp.example, 10.0.0.0/8")
  Proxy::from_env()    http_proxy (lower case only), https_proxy / HTTPS_PROXY, all_proxy /
                       ALL_PROXY, no_proxy / NO_PROXY -- as curl reads them: HTTP_PROXY in
                       upper case is left alone, since a CGI program gets the request's
                       "Proxy:" header as that variable (httpoxy, CVE-2016-5385 and others)
  proxy.for_url(&url) -> Option<&Endpoint>

http:// goes to the proxy as an absolute-form request (RFC 9112 3.2.2); https:// through a
CONNECT tunnel (RFC 9110 9.3.6), in which TLS checks the server itself, not the proxy.  Only
plain-HTTP proxies: an https:// or socks proxy URL is refused (None).  Loopback addresses and
localhost never go through a proxy (as Go's net/http): a local service is not sent elsewhere.
NO_PROXY: "*" for all, names (a leading "." or "*." optional) for themselves and the names
below them, IP addresses and CIDR ranges for URLs that name an address (no lookup); an entry
may end in ":port".
  • struct Endpoint a proxy server: where to connect and the credentials it gets (Basic)
    • host: String
    • port: u16

impl Endpoint

  • fn parse(s: &str) -> Option<Endpoint> "http://[user[:password]@]host[:port][/]" or "host[:port]" (http assumed); the port defaults to 80. None for another scheme (https://, socks5://), a path, or a bad host

  • fn with_auth(mut self, user: &str, password: &str) -> Endpoint with these credentials (Basic: "user:password" in base64)

  • fn authorization(&self) -> Option<&str> the Proxy-Authorization header's value

  • fn url(&self) -> Url the proxy as a URL of its own (where the client connects)

  • fn key(&self) -> String "host:port"

  • struct Proxy the proxies of a client: one per scheme, and the hosts that go direct

impl Proxy

  • fn none() -> Proxy no proxy (to add them one by one)
  • fn new(url: &str) -> Option<Proxy> one proxy for http and https (Endpoint::parse) -> None when it is not one
  • fn http(mut self, e: Endpoint) -> Proxy the proxy for http:// URLs
  • fn https(mut self, e: Endpoint) -> Proxy the proxy for https:// URLs (a CONNECT tunnel)
  • fn no_proxy(mut self, list: &str) -> Proxy hosts that go direct: a comma-separated list as NO_PROXY writes it (entries that are not one are left out)
  • fn from_env() -> Option<Proxy> the proxies the environment names (see the module header); None when it names none
  • fn from_vars(get: &dyn Fn(&str) -> Option<String>) -> Option<Proxy> from_env with the variables from get (tests, or a configuration of the app's own)
  • fn bypass(&self, url: &Url) -> bool whether a URL goes direct: loopback, localhost, or an entry of no_proxy
  • fn for_url(&self, url: &Url) -> Option<&Endpoint> the proxy a request to url goes through (None: direct)

Source: docs/API.md in the JFLib repository.