pub struct Proxy {
intercept: Intercept,
no_proxy: Option<NoProxy>,
}Expand description
Configuration of a proxy that a Client should pass requests to.
A Proxy has a couple pieces to it:
- a URL of how to talk to the proxy
- rules on what
Clientrequests should be directed to the proxy
For instance, let’s look at Proxy::http:
let proxy = reqwest::Proxy::http("https://secure.example")?;This proxy will intercept all HTTP requests, and make use of the proxy
at https://secure.example. A request to http://hyper.rs will talk
to your proxy. A request to https://hyper.rs will not.
Multiple Proxy rules can be configured for a Client. The Client will
check each Proxy in the order it was added. This could mean that a
Proxy added first with eager intercept rules, such as Proxy::all,
would prevent a Proxy later in the list from ever working, so take care.
By enabling the "socks" feature it is possible to use a socks proxy:
let proxy = reqwest::Proxy::http("socks5://192.168.1.1:9000")?;Fields§
§intercept: Intercept§no_proxy: Option<NoProxy>Implementations§
Source§impl Proxy
impl Proxy
Sourcepub fn http<U>(proxy_scheme: U) -> Result<Proxy, Error>where
U: IntoProxyScheme,
pub fn http<U>(proxy_scheme: U) -> Result<Proxy, Error>where
U: IntoProxyScheme,
Proxy all HTTP traffic to the passed URL.
§Example
let client = reqwest::Client::builder()
.proxy(reqwest::Proxy::http("https://my.prox")?)
.build()?;Sourcepub fn https<U>(proxy_scheme: U) -> Result<Proxy, Error>where
U: IntoProxyScheme,
pub fn https<U>(proxy_scheme: U) -> Result<Proxy, Error>where
U: IntoProxyScheme,
Proxy all HTTPS traffic to the passed URL.
§Example
let client = reqwest::Client::builder()
.proxy(reqwest::Proxy::https("https://example.prox:4545")?)
.build()?;Sourcepub fn all<U>(proxy_scheme: U) -> Result<Proxy, Error>where
U: IntoProxyScheme,
pub fn all<U>(proxy_scheme: U) -> Result<Proxy, Error>where
U: IntoProxyScheme,
Proxy all traffic to the passed URL.
§Example
let client = reqwest::Client::builder()
.proxy(reqwest::Proxy::all("http://pro.xy")?)
.build()?;Sourcepub fn custom<F, U>(fun: F) -> Proxy
pub fn custom<F, U>(fun: F) -> Proxy
Provide a custom function to determine what traffic to proxy to where.
§Example
let target = reqwest::Url::parse("https://my.prox")?;
let client = reqwest::Client::builder()
.proxy(reqwest::Proxy::custom(move |url| {
if url.host_str() == Some("hyper.rs") {
Some(target.clone())
} else {
None
}
}))
.build()?;Sourcepub fn basic_auth(self, username: &str, password: &str) -> Proxy
pub fn basic_auth(self, username: &str, password: &str) -> Proxy
Set the Proxy-Authorization header using Basic auth.
§Example
let proxy = reqwest::Proxy::https("http://localhost:1234")?
.basic_auth("Aladdin", "open sesame");Sourcepub fn custom_http_auth(self, header_value: HeaderValue) -> Proxy
pub fn custom_http_auth(self, header_value: HeaderValue) -> Proxy
Set the Proxy-Authorization header to a specified value.
§Example
let proxy = reqwest::Proxy::https("http://localhost:1234")?
.custom_http_auth(HeaderValue::from_static("justletmeinalreadyplease"));