@@ -118,14 +118,17 @@ impl<Connector, C> Client<
118118 }
119119}
120120
121+ #[cfg(all(feature = "client-tls", any(target_os = "macos", target_os = "windows", target_os = "ios")))]
122+ type HyperHttpsConnector = hyper_tls::HttpsConnector<hyper_util::client::legacy::connect::HttpConnector>;
123+
124+ #[cfg(all(feature = "client-tls", not(any(target_os = "macos", target_os = "windows", target_os = "ios"))))]
125+ type HyperHttpsConnector = hyper_openssl::client::legacy::HttpsConnector<hyper_util::client::legacy::connect::HttpConnector>;
126+
121127#[derive(Debug, Clone)]
122128pub enum HyperClient {
123129 Http(hyper_util::client::legacy::Client<hyper_util::client::legacy::connect::HttpConnector, BoxBody<Bytes, Infallible>>),
124- #[cfg(any(
125- all(feature = "client-tls", any(target_os = "macos", target_os = "windows", target_os = "ios")),
126- all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios")))
127- ))]
128- Https(hyper_util::client::legacy::Client<HttpsConnector, BoxBody<Bytes, Infallible>>),
130+ #[cfg(feature = "client-tls")]
131+ Https(hyper_util::client::legacy::Client<HyperHttpsConnector, BoxBody<Bytes, Infallible>>),
129132}
130133
131134impl Service<Request<BoxBody<Bytes, Infallible>>> for HyperClient {
@@ -136,10 +139,7 @@ impl Service<Request<BoxBody<Bytes, Infallible>>> for HyperClient {
136139 fn call(&self, req: Request<BoxBody<Bytes, Infallible>>) -> Self::Future {
137140 match self {
138141 HyperClient::Http(client) => client.request(req),
139- #[cfg(any(
140- all(feature = "client-tls", any(target_os = "macos", target_os = "windows", target_os = "ios")),
141- all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios")))
142- ))]
142+ #[cfg(feature = "client-tls")]
143143 HyperClient::Https(client) => client.request(req),
144144 }
145145 }
@@ -166,20 +166,15 @@ impl<C> Client<DropContextService<HyperClient, C>, C> where
166166 " http" => {
167167 HyperClient::Http(hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new()).build(connector.build()))
168168 } ,
169- #[cfg(any(
170- all(feature = "client-tls", any(target_os = "macos", target_os = "windows", target_os = "ios")),
171- all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios")))
172- ))]
169+ #[cfg(feature = "client-tls")]
173170 "https" => {
174- let connector = connector.https()
175- .build()
176- .map_err(ClientInitError::SslError)?;
177- HyperClient::Https(hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new()).build(connector))
171+ let https_connector = connector
172+ .https()
173+ .build()
174+ .map_err(ClientInitError::SslError)?;
175+ HyperClient::Https(hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new()).build(https_connector))
178176 } ,
179- #[cfg(not(any(
180- all(feature = "client-tls", any(target_os = "macos", target_os = "windows", target_os = "ios")),
181- all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios")))
182- )))]
177+ #[cfg(not(feature = "client-tls"))]
183178 "https" => {
184179 return Err(ClientInitError::TlsNotEnabled);
185180 } ,
@@ -228,13 +223,10 @@ impl<C> Client<
228223#[cfg(all(feature = "client-tls", any(target_os = "macos", target_os = "windows", target_os = "ios")))]
229224type HttpsConnector = hyper_tls::HttpsConnector<hyper _util::client::legacy::connect::HttpConnector >;
230225
231- #[cfg(all(feature = "client-openssl ", not(any(target_os = "macos", target_os = "windows", target_os = "ios"))))]
226+ #[cfg(all(feature = "client-tls ", not(any(target_os = "macos", target_os = "windows", target_os = "ios"))))]
232227type HttpsConnector = hyper_openssl::client::legacy::HttpsConnector<hyper _util::client::legacy::connect::HttpConnector >;
233228
234- #[cfg(any(
235- all(feature = "client-tls", any(target_os = "macos", target_os = "windows", target_os = "ios")),
236- all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios")))
237- ))]
229+ #[cfg(feature = "client-tls")]
238230impl<C > Client<
239231 DropContextService<
240232 hyper_util::service::TowerToHyperService<
@@ -249,10 +241,25 @@ impl<C> Client<
249241> where
250242 C: Clone + Send + Sync + 'static
251243{
252- /// Create a client with a TLS connection to the server
244+ /// Create a client with a TLS connection to the server using native-tls.
253245 ///
254246 /// # Arguments
255- /// * `base_path` - base path of the client API, i.e. " <http://www.my-api-implementation.com>"
247+ /// * `base_path` - base path of the client API, i.e. " <https://www.my-api-implementation.com>"
248+ #[cfg(any(target_os = " macos" , target_os = " windows" , target_os = " ios" ))]
249+ pub fn try_new_https(base_path: &str) -> Result< Self, ClientInitError>
250+ {
251+ let https_connector = Connector::builder()
252+ .https()
253+ .build()
254+ .map_err(ClientInitError::SslError)?;
255+ Self::try_new_with_connector(base_path, Some(" https" ), https_connector)
256+ }
257+
258+ /// Create a client with a TLS connection to the server using OpenSSL.
259+ ///
260+ /// # Arguments
261+ /// * `base_path` - base path of the client API, i.e. "<https: //www.my-api-implementation.com >"
262+ #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
256263 pub fn try_new_https(base_path: &str) -> Result<Self , ClientInitError >
257264 {
258265 let https_connector = Connector::builder()
@@ -265,9 +272,9 @@ impl<C> Client<
265272 /// Create a client with a TLS connection to the server using a pinned certificate
266273 ///
267274 /// # Arguments
268- /// * `base_path` - base path of the client API, i.e. "<http : //www.my-api-implementation.com >"
275+ /// * `base_path` - base path of the client API, i.e. "<https : //www.my-api-implementation.com >"
269276 /// * `ca_certificate` - Path to CA certificate used to authenticate the server
270- #[cfg(all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios") )))]
277+ #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
271278 pub fn try_new_https_pinned<CA >(
272279 base_path: &str,
273280 ca_certificate: CA,
@@ -286,11 +293,11 @@ impl<C> Client<
286293 /// Create a client with a mutually authenticated TLS connection to the server.
287294 ///
288295 /// # Arguments
289- /// * `base_path` - base path of the client API, i.e. "<http : //www.my-api-implementation.com >"
296+ /// * `base_path` - base path of the client API, i.e. "<https : //www.my-api-implementation.com >"
290297 /// * `ca_certificate` - Path to CA certificate used to authenticate the server
291298 /// * `client_key` - Path to the client private key
292299 /// * `client_certificate` - Path to the client's public certificate associated with the private key
293- #[cfg(all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios") )))]
300+ #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
294301 pub fn try_new_https_mutual<CA , K, D >(
295302 base_path: &str,
296303 ca_certificate: CA,
@@ -356,7 +363,7 @@ pub enum ClientInitError {
356363 SslError(native_tls::Error),
357364
358365 /// SSL Connection Error
359- #[cfg(all(feature = " client-openssl " , not (any(target_os = " macos" , target_os = " windows" , target_os = " ios" ))))]
366+ #[cfg(all(feature = " client-tls " , not (any(target_os = " macos" , target_os = " windows" , target_os = " ios" ))))]
360367 SslError(openssl::error::ErrorStack),
361368}
362369
0 commit comments