Allow TLS client config to be overridden

See: https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html
This commit is contained in:
Rob Young
2020-05-11 21:30:01 +01:00
committed by Martin Algesten
parent bbfd125025
commit 2e3a75166d
4 changed files with 133 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
use std::io::Read;
use std::sync::{Arc, Mutex};
#[cfg(feature = "tls")]
use std::fmt;
use lazy_static::lazy_static;
use qstring::QString;
@@ -46,6 +48,8 @@ pub struct Request {
pub(crate) timeout_write: u64,
pub(crate) redirects: u32,
pub(crate) proxy: Option<crate::proxy::Proxy>,
#[cfg(feature = "tls")]
pub(crate) tls_config: Option<TLSClientConfig>,
}
impl ::std::fmt::Debug for Request {
@@ -554,4 +558,31 @@ impl Request {
self.proxy = Some(proxy);
self
}
/// Set the TLS client config to use for the connection.
///
/// See [`ClientConfig`](https://docs.rs/rustls/latest/rustls/struct.ClientConfig.html).
///
/// Example:
/// ```
/// let tls_config = std::sync::Arc::new(rustls::ClientConfig::new());
/// let req = ureq::post("https://cool.server")
/// .set_tls_config(tls_config.clone());
/// ```
#[cfg(feature = "tls")]
pub fn set_tls_config(&mut self, tls_config: Arc<rustls::ClientConfig>) -> &mut Request {
self.tls_config = Some(TLSClientConfig(tls_config));
self
}
}
#[cfg(feature = "tls")]
#[derive(Clone)]
pub(crate) struct TLSClientConfig(pub(crate) Arc<rustls::ClientConfig>);
#[cfg(feature = "tls")]
impl fmt::Debug for TLSClientConfig {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("TLSClientConfig").finish()
}
}