diff --git a/src/async_impl/client.rs b/src/async_impl/client.rs index 77f14f71b..64583c03e 100644 --- a/src/async_impl/client.rs +++ b/src/async_impl/client.rs @@ -239,80 +239,47 @@ impl ClientBuilder { }) } - /// Set that all sockets have `SO_NODELAY` set to `true`. - pub fn tcp_nodelay(mut self) -> ClientBuilder { - self.config.nodelay = true; - self - } - - /// Use native TLS backend. - #[cfg(feature = "default-tls")] - pub fn use_default_tls(mut self) -> ClientBuilder { - self.config.tls = TlsBackend::Default; - self - } - - /// Use rustls TLS backend. - #[cfg(feature = "rustls-tls")] - pub fn use_rustls_tls(mut self) -> ClientBuilder { - self.config.tls = TlsBackend::Rustls; - self - } - - /// Add a custom root certificate. - /// - /// This can be used to connect to a server that has a self-signed - /// certificate for example. - #[cfg(feature = "tls")] - pub fn add_root_certificate(mut self, cert: Certificate) -> ClientBuilder { - self.config.root_certs.push(cert); - self - } + // Higher-level options - /// Sets the identity to be used for client certificate authentication. - #[cfg(feature = "tls")] - pub fn identity(mut self, identity: Identity) -> ClientBuilder { - self.config.identity = Some(identity); - self - } - - /// Controls the use of hostname verification. + /// Sets the default headers for every request. /// - /// Defaults to `false`. + /// # Example /// - /// # Warning + /// ```rust + /// use reqwest::header; + /// # async fn doc() -> Result<(), reqwest::Error> { + /// let mut headers = header::HeaderMap::new(); + /// headers.insert(header::AUTHORIZATION, header::HeaderValue::from_static("secret")); /// - /// You should think very carefully before you use this method. If - /// hostname verification is not used, any valid certificate for any - /// site will be trusted for use from any other. This introduces a - /// significant vulnerability to man-in-the-middle attacks. - #[cfg(feature = "default-tls")] - pub fn danger_accept_invalid_hostnames( - mut self, - accept_invalid_hostname: bool, - ) -> ClientBuilder { - self.config.hostname_verification = !accept_invalid_hostname; - self - } - - /// Controls the use of certificate validation. + /// // get a client builder + /// let client = reqwest::Client::builder() + /// .default_headers(headers) + /// .build()?; + /// let res = client.get("https://www.rust-lang.org").send().await?; + /// # Ok(()) + /// # } + /// ``` /// - /// Defaults to `false`. + /// Override the default headers: /// - /// # Warning + /// ```rust + /// use reqwest::header; + /// # async fn doc() -> Result<(), reqwest::Error> { + /// let mut headers = header::HeaderMap::new(); + /// headers.insert(header::AUTHORIZATION, header::HeaderValue::from_static("secret")); /// - /// You should think very carefully before using this method. If - /// invalid certificates are trusted, *any* certificate for *any* site - /// will be trusted for use. This includes expired certificates. This - /// introduces significant vulnerabilities, and should only be used - /// as a last resort. - #[cfg(feature = "tls")] - pub fn danger_accept_invalid_certs(mut self, accept_invalid_certs: bool) -> ClientBuilder { - self.config.certs_verification = !accept_invalid_certs; - self - } - - /// Sets the default headers for every request. + /// // get a client builder + /// let client = reqwest::Client::builder() + /// .default_headers(headers) + /// .build()?; + /// let res = client + /// .get("https://www.rust-lang.org") + /// .header(header::AUTHORIZATION, "token") + /// .send() + /// .await?; + /// # Ok(()) + /// # } + /// ``` pub fn default_headers(mut self, headers: HeaderMap) -> ClientBuilder { for (key, value) in headers.iter() { self.config.headers.insert(key, value.clone()); @@ -320,6 +287,27 @@ impl ClientBuilder { self } + + /// Enable a persistent cookie store for the client. + /// + /// Cookies received in responses will be preserved and included in + /// additional requests. + /// + /// By default, no cookie store is used. + /// + /// # Optional + /// + /// This requires the optional `cookies` feature to be enabled. + #[cfg(feature = "cookies")] + pub fn cookie_store(mut self, enable: bool) -> ClientBuilder { + self.config.cookie_store = if enable { + Some(cookie::CookieStore::default()) + } else { + None + }; + self + } + /// Enable auto gzip decompression by checking the `Content-Encoding` response header. /// /// If auto gzip decompresson is turned on: @@ -359,6 +347,26 @@ impl ClientBuilder { } } + // Redirect options + + /// Set a `RedirectPolicy` for this client. + /// + /// Default will follow redirects up to a maximum of 10. + pub fn redirect(mut self, policy: RedirectPolicy) -> ClientBuilder { + self.config.redirect_policy = policy; + self + } + + /// Enable or disable automatic setting of the `Referer` header. + /// + /// Default is `true`. + pub fn referer(mut self, enable: bool) -> ClientBuilder { + self.config.referer = enable; + self + } + + // Proxy options + /// Add a `Proxy` to the list of proxies the `Client` will use. pub fn proxy(mut self, proxy: Proxy) -> ClientBuilder { self.config.proxies.push(proxy); @@ -384,21 +392,7 @@ impl ClientBuilder { self } - /// Set a `RedirectPolicy` for this client. - /// - /// Default will follow redirects up to a maximum of 10. - pub fn redirect(mut self, policy: RedirectPolicy) -> ClientBuilder { - self.config.redirect_policy = policy; - self - } - - /// Enable or disable automatic setting of the `Referer` header. - /// - /// Default is `true`. - pub fn referer(mut self, enable: bool) -> ClientBuilder { - self.config.referer = enable; - self - } + // Timeout options /// Enables a request timeout. /// @@ -411,17 +405,24 @@ impl ClientBuilder { self } - /// Sets the maximum idle connection per host allowed in the pool. + /// Set a timeout for only the connect phase of a `Client`. /// - /// Default is usize::MAX (no limit). - pub fn max_idle_per_host(mut self, max: usize) -> ClientBuilder { - self.config.max_idle_per_host = max; + /// Default is `None`. + /// + /// # Note + /// + /// This **requires** the futures be executed in a tokio runtime with + /// a tokio timer enabled. + pub fn connect_timeout(mut self, timeout: Duration) -> ClientBuilder { + self.config.connect_timeout = Some(timeout); self } - /// Only use HTTP/2. - pub fn h2_prior_knowledge(mut self) -> ClientBuilder { - self.config.http2_only = true; + // HTTP options + + /// Sets the maximum idle connection per host allowed in the pool. + pub fn max_idle_per_host(mut self, max: usize) -> ClientBuilder { + self.config.max_idle_per_host = max; self } @@ -431,20 +432,31 @@ impl ClientBuilder { self } - /// Set a timeout for only the connect phase of a `Client`. - /// - /// Default is `None`. - /// - /// # Note - /// - /// This **requires** the futures be executed in a tokio runtime with - /// a tokio timer enabled. - pub fn connect_timeout(mut self, timeout: Duration) -> ClientBuilder { - self.config.connect_timeout = Some(timeout); + /// Only use HTTP/2. + pub fn http2_prior_knowledge(mut self) -> ClientBuilder { + self.config.http2_only = true; self } - /// Bind to a local IP Address + // TCP options + + /// Set that all sockets have `SO_NODELAY` set to `true`. + pub fn tcp_nodelay(mut self) -> ClientBuilder { + self.config.nodelay = true; + self + } + + /// Bind to a local IP Address. + /// + /// # Example + /// + /// ``` + /// use std::net::IpAddr; + /// let local_addr = IpAddr::from([12, 4, 1, 8]); + /// let client = reqwest::Client::builder() + /// .local_address(local_addr) + /// .build().unwrap(); + /// ``` pub fn local_address(mut self, addr: T) -> ClientBuilder where T: Into>, @@ -453,25 +465,110 @@ impl ClientBuilder { self } - /// Enable a persistent cookie store for the client. + // TLS options + + /// Add a custom root certificate. /// - /// Cookies received in responses will be preserved and included in - /// additional requests. + /// This can be used to connect to a server that has a self-signed + /// certificate for example. /// - /// By default, no cookie store is used. + /// # Optional + /// + /// This requires the optional `default-tls` or `rustls-tls` feature to be + /// enabled. + #[cfg(feature = "tls")] + pub fn add_root_certificate(mut self, cert: Certificate) -> ClientBuilder { + self.config.root_certs.push(cert); + self + } + + /// Sets the identity to be used for client certificate authentication. /// /// # Optional /// - /// This requires the optional `cookies` feature to be enabled. - #[cfg(feature = "cookies")] - pub fn cookie_store(mut self, enable: bool) -> ClientBuilder { - self.config.cookie_store = if enable { - Some(cookie::CookieStore::default()) - } else { - None - }; + /// This requires the optional `default-tls` or `rustls-tls` feature to be + /// enabled. + #[cfg(feature = "tls")] + pub fn identity(mut self, identity: Identity) -> ClientBuilder { + self.config.identity = Some(identity); + self + } + + /// Controls the use of hostname verification. + /// + /// Defaults to `false`. + /// + /// # Warning + /// + /// You should think very carefully before you use this method. If + /// hostname verification is not used, any valid certificate for any + /// site will be trusted for use from any other. This introduces a + /// significant vulnerability to man-in-the-middle attacks. + /// + /// # Optional + /// + /// This requires the optional `default-tls` feature to be enabled. + #[cfg(feature = "default-tls")] + pub fn danger_accept_invalid_hostnames( + mut self, + accept_invalid_hostname: bool, + ) -> ClientBuilder { + self.config.hostname_verification = !accept_invalid_hostname; self } + + /// Controls the use of certificate validation. + /// + /// Defaults to `false`. + /// + /// # Warning + /// + /// You should think very carefully before using this method. If + /// invalid certificates are trusted, *any* certificate for *any* site + /// will be trusted for use. This includes expired certificates. This + /// introduces significant vulnerabilities, and should only be used + /// as a last resort. + /// + /// # Optional + /// + /// This requires the optional `default-tls` or `rustls-tls` feature to be + /// enabled. + #[cfg(feature = "tls")] + pub fn danger_accept_invalid_certs(mut self, accept_invalid_certs: bool) -> ClientBuilder { + self.config.certs_verification = !accept_invalid_certs; + self + } + + /// Force using the native TLS backend. + /// + /// Since multiple TLS backends can be optionally enabled, this option will + /// force the `native-tls` backend to be used for this `Client`. + /// + /// # Optional + /// + /// This requires the optional `default-tls` feature to be enabled. + #[cfg(feature = "default-tls")] + pub fn use_default_tls(mut self) -> ClientBuilder { + self.config.tls = TlsBackend::Default; + self + } + + + /// Force using the Rustls TLS backend. + /// + /// Since multiple TLS backends can be optionally enabled, this option will + /// force the `rustls` backend to be used for this `Client`. + /// + /// # Optional + /// + /// This requires the optional `rustls-tls` feature to be enabled. + #[cfg(feature = "rustls-tls")] + pub fn use_rustls_tls(mut self) -> ClientBuilder { + self.config.tls = TlsBackend::Rustls; + self + } + + } type HyperClient = hyper::Client; diff --git a/src/blocking/client.rs b/src/blocking/client.rs index 38b8b99ad..f1edb06db 100644 --- a/src/blocking/client.rs +++ b/src/blocking/client.rs @@ -84,134 +84,8 @@ impl ClientBuilder { ClientHandle::new(self).map(|handle| Client { inner: handle }) } - /// Disable proxy setting. - pub fn no_proxy(self) -> ClientBuilder { - self.with_inner(move |inner| inner.no_proxy()) - } - /// Enable system proxy setting. - pub fn use_sys_proxy(self) -> ClientBuilder { - self.with_inner(move |inner| inner.use_sys_proxy()) - } - - /// Set that all sockets have `SO_NODELAY` set to `true`. - pub fn tcp_nodelay(self) -> ClientBuilder { - self.with_inner(move |inner| inner.tcp_nodelay()) - } - - /// Use native TLS backend. - #[cfg(feature = "default-tls")] - pub fn use_default_tls(self) -> ClientBuilder { - self.with_inner(move |inner| inner.use_default_tls()) - } - - /// Use rustls TLS backend. - #[cfg(feature = "rustls-tls")] - pub fn use_rustls_tls(self) -> ClientBuilder { - self.with_inner(move |inner| inner.use_rustls_tls()) - } - - /// Add a custom root certificate. - /// - /// This allows connecting to a server that has a self-signed - /// certificate for example. This **does not** replace the existing - /// trusted store. - /// - /// # Example - /// ``` - /// # use std::fs::File; - /// # use std::io::Read; - /// # fn build_client() -> Result<(), Box> { - /// // read a local binary DER encoded certificate - /// let mut buf = Vec::new(); - /// File::open("my-cert.der")?.read_to_end(&mut buf)?; - /// - /// // create a certificate - /// let cert = reqwest::Certificate::from_der(&buf)?; - /// - /// // get a client builder - /// let client = reqwest::blocking::Client::builder() - /// .add_root_certificate(cert) - /// .build()?; - /// # drop(client); - /// # Ok(()) - /// # } - /// ``` - /// - /// # Errors - /// - /// This method fails if adding root certificate was unsuccessful. - #[cfg(feature = "tls")] - pub fn add_root_certificate(self, cert: Certificate) -> ClientBuilder { - self.with_inner(move |inner| inner.add_root_certificate(cert)) - } - - /// Sets the identity to be used for client certificate authentication. - /// - /// # Example - /// - /// ``` - /// # use std::fs::File; - /// # use std::io::Read; - /// # fn build_client() -> Result<(), Box> { - /// // read a local PKCS12 bundle - /// let mut buf = Vec::new(); - /// - /// #[cfg(feature = "default-tls")] - /// File::open("my-ident.pfx")?.read_to_end(&mut buf)?; - /// #[cfg(feature = "rustls-tls")] - /// File::open("my-ident.pem")?.read_to_end(&mut buf)?; - /// - /// #[cfg(feature = "default-tls")] - /// // create an Identity from the PKCS#12 archive - /// let pkcs12 = reqwest::Identity::from_pkcs12_der(&buf, "my-privkey-password")?; - /// #[cfg(feature = "rustls-tls")] - /// // create an Identity from the PEM file - /// let pkcs12 = reqwest::Identity::from_pem(&buf)?; - /// - /// // get a client builder - /// let client = reqwest::blocking::Client::builder() - /// .identity(pkcs12) - /// .build()?; - /// # drop(client); - /// # Ok(()) - /// # } - /// ``` - #[cfg(feature = "tls")] - pub fn identity(self, identity: Identity) -> ClientBuilder { - self.with_inner(move |inner| inner.identity(identity)) - } - - /// Controls the use of hostname verification. - /// - /// Defaults to `false`. - /// - /// # Warning - /// - /// You should think very carefully before you use this method. If - /// hostname verification is not used, any valid certificate for any - /// site will be trusted for use from any other. This introduces a - /// significant vulnerability to man-in-the-middle attacks. - #[cfg(feature = "default-tls")] - pub fn danger_accept_invalid_hostnames(self, accept_invalid_hostname: bool) -> ClientBuilder { - self.with_inner(|inner| inner.danger_accept_invalid_hostnames(accept_invalid_hostname)) - } - - /// Controls the use of certificate validation. - /// - /// Defaults to `false`. - /// - /// # Warning - /// - /// You should think very carefully before using this method. If - /// invalid certificates are trusted, *any* certificate for *any* site - /// will be trusted for use. This includes expired certificates. This - /// introduces significant vulnerabilities, and should only be used - /// as a last resort. - #[cfg(feature = "tls")] - pub fn danger_accept_invalid_certs(self, accept_invalid_certs: bool) -> ClientBuilder { - self.with_inner(|inner| inner.danger_accept_invalid_certs(accept_invalid_certs)) - } + // Higher-level options /// Sets the default headers for every request. /// @@ -219,7 +93,7 @@ impl ClientBuilder { /// /// ```rust /// use reqwest::header; - /// # fn build_client() -> Result<(), Box> { + /// # fn build_client() -> Result<(), reqwest::Error> { /// let mut headers = header::HeaderMap::new(); /// headers.insert(header::AUTHORIZATION, header::HeaderValue::from_static("secret")); /// @@ -236,7 +110,7 @@ impl ClientBuilder { /// /// ```rust /// use reqwest::header; - /// # fn build_client() -> Result<(), Box> { + /// # fn build_client() -> Result<(), reqwest::Error> { /// let mut headers = header::HeaderMap::new(); /// headers.insert(header::AUTHORIZATION, header::HeaderValue::from_static("secret")); /// @@ -255,6 +129,21 @@ impl ClientBuilder { self.with_inner(move |inner| inner.default_headers(headers)) } + /// Enable a persistent cookie store for the client. + /// + /// Cookies received in responses will be preserved and included in + /// additional requests. + /// + /// By default, no cookie store is used. + /// + /// # Optional + /// + /// This requires the optional `cookies` feature to be enabled. + #[cfg(feature = "cookies")] + pub fn cookie_store(self, enable: bool) -> ClientBuilder { + self.with_inner(|inner| inner.cookie_store(enable)) + } + /// Enable auto gzip decompression by checking the `Content-Encoding` response header. /// /// If auto gzip decompresson is turned on: @@ -285,10 +174,7 @@ impl ClientBuilder { self.with_inner(|inner| inner.no_gzip()) } - /// Add a `Proxy` to the list of proxies the `Client` will use. - pub fn proxy(self, proxy: Proxy) -> ClientBuilder { - self.with_inner(move |inner| inner.proxy(proxy)) - } + // Redirect options /// Set a `RedirectPolicy` for this client. /// @@ -304,6 +190,25 @@ impl ClientBuilder { self.with_inner(|inner| inner.referer(enable)) } + // Proxy options + + /// Add a `Proxy` to the list of proxies the `Client` will use. + pub fn proxy(self, proxy: Proxy) -> ClientBuilder { + self.with_inner(move |inner| inner.proxy(proxy)) + } + + /// Disable proxy setting. + pub fn no_proxy(self) -> ClientBuilder { + self.with_inner(move |inner| inner.no_proxy()) + } + + /// Enable system proxy setting. + pub fn use_sys_proxy(self) -> ClientBuilder { + self.with_inner(move |inner| inner.use_sys_proxy()) + } + + // Timeout options + /// Set a timeout for connect, read and write operations of a `Client`. /// /// Default is 30 seconds. @@ -317,13 +222,6 @@ impl ClientBuilder { self } - /// Sets the maximum idle connection per host allowed in the pool. - /// - /// Default is usize::MAX (no limit). - pub fn max_idle_per_host(self, max: usize) -> ClientBuilder { - self.with_inner(move |inner| inner.max_idle_per_host(max)) - } - /// Set a timeout for only the connect phase of a `Client`. /// /// Default is `None`. @@ -339,41 +237,31 @@ impl ClientBuilder { } } - fn with_inner(mut self, func: F) -> ClientBuilder - where - F: FnOnce(async_impl::ClientBuilder) -> async_impl::ClientBuilder, - { - self.inner = func(self.inner); - self - } + // HTTP options - /// Only use HTTP/2. - /// - /// # Example - /// - /// ``` - /// let client = reqwest::blocking::Client::builder() - /// .h2_prior_knowledge() - /// .build().unwrap(); - /// ``` - pub fn h2_prior_knowledge(self) -> ClientBuilder { - self.with_inner(|inner| inner.h2_prior_knowledge()) + /// Sets the maximum idle connection per host allowed in the pool. + pub fn max_idle_per_host(self, max: usize) -> ClientBuilder { + self.with_inner(move |inner| inner.max_idle_per_host(max)) } /// Enable case sensitive headers. - /// - /// # Example - /// - /// ``` - /// let client = reqwest::blocking::Client::builder() - /// .http1_title_case_headers() - /// .build().unwrap(); - /// ``` pub fn http1_title_case_headers(self) -> ClientBuilder { self.with_inner(|inner| inner.http1_title_case_headers()) } - /// Bind to a local IP Address + /// Only use HTTP/2. + pub fn http2_prior_knowledge(self) -> ClientBuilder { + self.with_inner(|inner| inner.http2_prior_knowledge()) + } + + // TCP options + + /// Set that all sockets have `SO_NODELAY` set to `true`. + pub fn tcp_nodelay(self) -> ClientBuilder { + self.with_inner(move |inner| inner.tcp_nodelay()) + } + + /// Bind to a local IP Address. /// /// # Example /// @@ -391,28 +279,145 @@ impl ClientBuilder { self.with_inner(move |inner| inner.local_address(addr)) } - /// Enable a persistent cookie store for the client. + // TLS options + + /// Add a custom root certificate. /// - /// Cookies received in responses will be preserved and included in - /// additional requests. + /// This allows connecting to a server that has a self-signed + /// certificate for example. This **does not** replace the existing + /// trusted store. /// - /// By default, no cookie store is used. + /// # Example + /// + /// ``` + /// # use std::fs::File; + /// # use std::io::Read; + /// # fn build_client() -> Result<(), Box> { + /// // read a local binary DER encoded certificate + /// let der = std::fs::read("my-cert.der")?; + /// + /// // create a certificate + /// let cert = reqwest::Certificate::from_der(&der)?; + /// + /// // get a client builder + /// let client = reqwest::blocking::Client::builder() + /// .add_root_certificate(cert) + /// .build()?; + /// # drop(client); + /// # Ok(()) + /// # } + /// ``` + /// + /// # Optional + /// + /// This requires the optional `default-tls` or `rustls-tls` feature to be + /// enabled. + #[cfg(feature = "tls")] + pub fn add_root_certificate(self, cert: Certificate) -> ClientBuilder { + self.with_inner(move |inner| inner.add_root_certificate(cert)) + } + + /// Sets the identity to be used for client certificate authentication. /// /// # Example /// /// ``` + /// # use std::fs::File; + /// # use std::io::Read; + /// # fn build_client() -> Result<(), Box> { + /// // read a local PKCS12 bundle + /// let mut buf = Vec::new(); + /// + /// #[cfg(feature = "default-tls")] + /// File::open("my-ident.pfx")?.read_to_end(&mut buf)?; + /// #[cfg(feature = "rustls-tls")] + /// File::open("my-ident.pem")?.read_to_end(&mut buf)?; + /// + /// #[cfg(feature = "default-tls")] + /// // create an Identity from the PKCS#12 archive + /// let pkcs12 = reqwest::Identity::from_pkcs12_der(&buf, "my-privkey-password")?; + /// #[cfg(feature = "rustls-tls")] + /// // create an Identity from the PEM file + /// let pkcs12 = reqwest::Identity::from_pem(&buf)?; + /// + /// // get a client builder /// let client = reqwest::blocking::Client::builder() - /// .cookie_store(true) - /// .build() - /// .unwrap(); + /// .identity(pkcs12) + /// .build()?; + /// # drop(client); + /// # Ok(()) + /// # } /// ``` + #[cfg(feature = "tls")] + pub fn identity(self, identity: Identity) -> ClientBuilder { + self.with_inner(move |inner| inner.identity(identity)) + } + + /// Controls the use of hostname verification. + /// + /// Defaults to `false`. + /// + /// # Warning + /// + /// You should think very carefully before you use this method. If + /// hostname verification is not used, any valid certificate for any + /// site will be trusted for use from any other. This introduces a + /// significant vulnerability to man-in-the-middle attacks. + #[cfg(feature = "default-tls")] + pub fn danger_accept_invalid_hostnames(self, accept_invalid_hostname: bool) -> ClientBuilder { + self.with_inner(|inner| inner.danger_accept_invalid_hostnames(accept_invalid_hostname)) + } + + /// Controls the use of certificate validation. + /// + /// Defaults to `false`. + /// + /// # Warning + /// + /// You should think very carefully before using this method. If + /// invalid certificates are trusted, *any* certificate for *any* site + /// will be trusted for use. This includes expired certificates. This + /// introduces significant vulnerabilities, and should only be used + /// as a last resort. + #[cfg(feature = "tls")] + pub fn danger_accept_invalid_certs(self, accept_invalid_certs: bool) -> ClientBuilder { + self.with_inner(|inner| inner.danger_accept_invalid_certs(accept_invalid_certs)) + } + + /// Force using the native TLS backend. + /// + /// Since multiple TLS backends can be optionally enabled, this option will + /// force the `native-tls` backend to be used for this `Client`. /// /// # Optional /// - /// This requires the optional `cookies` feature to be enabled. - #[cfg(feature = "cookies")] - pub fn cookie_store(self, enable: bool) -> ClientBuilder { - self.with_inner(|inner| inner.cookie_store(enable)) + /// This requires the optional `default-tls` feature to be enabled. + #[cfg(feature = "default-tls")] + pub fn use_default_tls(self) -> ClientBuilder { + self.with_inner(move |inner| inner.use_default_tls()) + } + + /// Force using the Rustls TLS backend. + /// + /// Since multiple TLS backends can be optionally enabled, this option will + /// force the `rustls` backend to be used for this `Client`. + /// + /// # Optional + /// + /// This requires the optional `rustls-tls` feature to be enabled. + #[cfg(feature = "rustls-tls")] + pub fn use_rustls_tls(self) -> ClientBuilder { + self.with_inner(move |inner| inner.use_rustls_tls()) + } + + // private + + fn with_inner(mut self, func: F) -> ClientBuilder + where + F: FnOnce(async_impl::ClientBuilder) -> async_impl::ClientBuilder, + { + self.inner = func(self.inner); + self } }