[−][src]Struct reqwest::Proxy
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
Client
requests 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.
Methods
impl Proxy
[src][−]
pub fn http<U: IntoUrl>(url: U) -> Result<Proxy>
[src][−]
Proxy all HTTP traffic to the passed URL.
Example
let client = reqwest::Client::builder() .proxy(reqwest::Proxy::http("https://my.prox")?) .build()?;
pub fn https<U: IntoUrl>(url: U) -> Result<Proxy>
[src][−]
Proxy all HTTPS traffic to the passed URL.
Example
let client = reqwest::Client::builder() .proxy(reqwest::Proxy::https("https://example.prox:4545")?) .build()?;
pub fn all<U: IntoUrl>(url: U) -> Result<Proxy>
[src][−]
Proxy all traffic to the passed URL.
Example
let client = reqwest::Client::builder() .proxy(reqwest::Proxy::all("http://pro.xy")?) .build()?;
pub fn custom<F>(fun: F) -> Proxy where
F: Fn(&Url) -> Option<Url> + Send + Sync + 'static,
[src][−]
F: Fn(&Url) -> Option<Url> + Send + Sync + 'static,
Provide a custom function to determine what traffix 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()?;
pub fn basic_auth(self, username: &str, password: &str) -> Proxy
[src][−]
Set the Proxy-Authorization
header using Basic auth.
Example
let proxy = reqwest::Proxy::https("http://localhost:1234")? .basic_auth("Aladdin", "open sesame");
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src][−]
impl<T, U> Into for T where
U: From<T>,
[src][−]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src][−]
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src][−]
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src][−]
impl<T> Borrow for T where
T: ?Sized,
[src][−]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src][−]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src][−]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src][−]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src][−]
impl<T> Any for T where
T: 'static + ?Sized,
[src][−]
T: 'static + ?Sized,