[][src]Crate env_proxy

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:

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);
}

Structs

ProxyUrl

A wrapper for the proxy URL retrieved from the environment.

Functions

for_url

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

for_url_str

Determine proxy parameters for a URL given as a string.