#env-var #http-proxy #https-proxy #no-proxy

proxyvars

Parser for the HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables, with a Go-like matcher for the NO_PROXY variable

4 releases

0.2.0 May 3, 2024
0.1.3 Apr 21, 2023
0.1.1 Apr 21, 2023
0.1.0 Apr 21, 2023

#57 in #http-proxy

Download history 89/week @ 2024-11-16 55/week @ 2024-11-23 93/week @ 2024-11-30 66/week @ 2024-12-07 62/week @ 2024-12-14 5/week @ 2024-12-28 18/week @ 2025-01-04 56/week @ 2025-01-11 12/week @ 2025-01-18 35/week @ 2025-01-25 65/week @ 2025-02-01 106/week @ 2025-02-08 29/week @ 2025-02-15 52/week @ 2025-02-22 10/week @ 2025-03-01

214 downloads per month

MIT license

19KB
341 lines

proxyvars

proxyvars is a parser for the HTTP_PROXY, HTTPS_PROXY and NO_PROXY environment variables, with NO_PROXY matcher based on Go's implementation.

This crate can:

  • Read HTTPS_PROXY and HTTP_PROXY and its lowercase variants
  • Read, parse and evaluate the NO_PROXY environment variables against a given URL
    • Supports CIDR
    • Supports IPv4/IPv6 address and optinal ports
    • Supports Hostnames and optinal ports
    • Supports Wildcard

Usage

if let Some(no_proxy) = proxyvars::no_proxy() {
    // This environment has NO_PROXY defined
    if no_proxy.matches("https://company.com") {
        // We should not use a proxy for this URL
    } else {
        // We should use a proxy for this URL, which are available at:
        let https_proxy = proxyvars::https_proxy();
        let http_proxy = proxyvars::http_proxy();
    }
}

Notes

  1. The implementation of the NO_PROXY matcher is heavily inspired by Go's implementation located at http/httpproxy/proxy.go.
  2. It's outside the scope of this crate to actually perform the proxying.

Dependencies

~775KB
~12K SLoC