Add proxy on agent. (#178)

This commit is contained in:
Jacob Hoffman-Andrews
2020-10-06 00:12:26 -07:00
committed by GitHub
parent 5b75deccef
commit e3138b0ace
3 changed files with 37 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ use crate::body::BodySize;
use crate::body::{Payload, SizedReader};
use crate::error::Error;
use crate::header::{self, Header};
use crate::proxy::Proxy;
use crate::unit::{self, Unit};
use crate::Response;
@@ -43,7 +44,7 @@ pub struct Request {
pub(crate) timeout_write: u64,
pub(crate) timeout: Option<time::Duration>,
pub(crate) redirects: u32,
pub(crate) proxy: Option<crate::proxy::Proxy>,
pub(crate) proxy: Option<Proxy>,
#[cfg(feature = "tls")]
pub(crate) tls_config: Option<TLSClientConfig>,
#[cfg(all(feature = "native-tls", not(feature = "tls")))]
@@ -559,12 +560,22 @@ impl Request {
/// .set_proxy(proxy)
/// .build();
/// ```
pub fn set_proxy(&mut self, proxy: crate::proxy::Proxy) -> &mut Request {
pub fn set_proxy(&mut self, proxy: Proxy) -> &mut Request {
self.proxy = Some(proxy);
self
}
/// Set the TLS client config to use for the connection.
pub(crate) fn proxy(&self) -> Option<Proxy> {
if let Some(proxy) = &self.proxy {
Some(proxy.clone())
} else if let Some(proxy) = &self.agent.lock().unwrap().proxy {
Some(proxy.clone())
} else {
None
}
}
/// Set the TLS client config to use for the connection. See [`ClientConfig`](https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html).
///
/// See [`ClientConfig`](https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html).
///