#proxy #environment #http #url

env_proxy

Determination of proxy parameters for a URL from the environment

7 unstable releases

0.4.1 Jul 7, 2020
0.4.0 Jul 29, 2019
0.3.1 Apr 28, 2019
0.3.0 Mar 8, 2019
0.1.0 Jun 19, 2016

#133 in Network programming

Download history 2422/week @ 2021-05-30 2819/week @ 2021-06-06 3651/week @ 2021-06-13 2701/week @ 2021-06-20 2994/week @ 2021-06-27 4375/week @ 2021-07-04 3502/week @ 2021-07-11 3760/week @ 2021-07-18 4194/week @ 2021-07-25 4175/week @ 2021-08-01 4447/week @ 2021-08-08 3172/week @ 2021-08-15 5176/week @ 2021-08-22 5163/week @ 2021-08-29 3974/week @ 2021-09-05 6162/week @ 2021-09-12

19,696 downloads per month
Used in 27 crates (11 directly)

MIT/Apache

24KB
373 lines

env_proxy

Build Status

Determination of proxy parameters for a URL from the environment.

See the documentation for API reference.

Getting Started

Add the following to the [dependencies] section of your Cargo.toml:

env_proxy = "0.3"

Also, import the crate in your crate root:

extern crate env_proxy;

Example

use url::Url;

let url = Url::parse("http://www.example.org").unwrap();
if let Some(proxy) = env_proxy::for_url(&url).host_port() {
    println!("Proxy host: {}", proxy.0);
    println!("Proxy port: {}", proxy.1);
}

License

This program is distributed under the terms of both the MIT license and the Apache License (Version 2.0), at your option.

See LICENSE-APACHE and LICENSE-MIT.


lib.rs:

Determine proxy parameters for a URL from the environment.

Environment variables are one way to request the use of an HTTP proxy server for outgoing connections in many command-line applications. Which environment variable will be used depends on the target URL and the convention used by the application (or, customarily, the connection library that it uses.)

This crate aims to replicate the convention of the curl library and offer it behind a simple API: in most cases, a single function, for_url(), which accepts a target URL and returns the proxy parameters, if applicable. The method for determining the parameters is described in detail in that function's documentation.

Getting Started

Add the following to the [dependencies] section of your Cargo.toml:

env_proxy = "0.3"

If you're using the 2015 edition of Rust, import the crate to your crate root:

extern crate env_proxy;

Examples

To determine proxy parameters for http://www.example.org:

# extern crate url;
# extern crate env_proxy;
# fn main() {
use env_proxy;
use url::Url;

let url = Url::parse("http://www.example.org").unwrap();
if let Some(proxy) = env_proxy::for_url(&url).host_port() {
    println!("Proxy host: {}", proxy.0);
    println!("Proxy port: {}", proxy.1);
}
# }

Dependencies

~1.5MB
~53K SLoC