@@ -121,6 +121,10 @@ impl<Connector, C> Client<
121121#[derive(Debug, Clone)]
122122pub enum HyperClient {
123123 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+ ))]
124128 Https(hyper_util::client::legacy::Client<HttpsConnector, BoxBody<Bytes, Infallible>>),
125129}
126130
@@ -132,7 +136,11 @@ impl Service<Request<BoxBody<Bytes, Infallible>>> for HyperClient {
132136 fn call(&self, req: Request<BoxBody<Bytes, Infallible>>) -> Self::Future {
133137 match self {
134138 HyperClient::Http(client) => client.request(req),
135- HyperClient::Https(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+ ))]
143+ HyperClient::Https(client) => client.request(req),
136144 }
137145 }
138146}
@@ -158,12 +166,23 @@ impl<C> Client<DropContextService<HyperClient, C>, C> where
158166 " http" => {
159167 HyperClient::Http(hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new()).build(connector.build()))
160168 } ,
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+ ))]
161173 "https" => {
162174 let connector = connector.https()
163175 .build()
164176 .map_err(ClientInitError::SslError)?;
165177 HyperClient::Https(hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new()).build(connector))
166178 } ,
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+ )))]
183+ "https" => {
184+ return Err(ClientInitError::TlsNotEnabled);
185+ } ,
167186 _ => {
168187 return Err(ClientInitError::InvalidScheme);
169188 }
@@ -206,12 +225,16 @@ impl<C> Client<
206225 }
207226}
208227
209- #[cfg(any(target_os = "macos", target_os = "windows", target_os = "ios"))]
228+ #[cfg(all(feature = "client-tls", any(target_os = "macos", target_os = "windows", target_os = "ios") ))]
210229type HttpsConnector = hyper_tls::HttpsConnector<hyper _util::client::legacy::connect::HttpConnector >;
211230
212- #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
231+ #[cfg(all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios") )))]
213232type HttpsConnector = hyper_openssl::client::legacy::HttpsConnector<hyper _util::client::legacy::connect::HttpConnector >;
214233
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+ ))]
215238impl<C > Client<
216239 DropContextService<
217240 hyper_util::service::TowerToHyperService<
@@ -244,7 +267,7 @@ impl<C> Client<
244267 /// # Arguments
245268 /// * `base_path` - base path of the client API, i.e. "<http: //www.my-api-implementation.com >"
246269 /// * `ca_certificate` - Path to CA certificate used to authenticate the server
247- #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
270+ #[cfg(all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios") )))]
248271 pub fn try_new_https_pinned<CA >(
249272 base_path: &str,
250273 ca_certificate: CA,
@@ -267,7 +290,7 @@ impl<C> Client<
267290 /// * `ca_certificate` - Path to CA certificate used to authenticate the server
268291 /// * `client_key` - Path to the client private key
269292 /// * `client_certificate` - Path to the client's public certificate associated with the private key
270- #[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))]
293+ #[cfg(all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios") )))]
271294 pub fn try_new_https_mutual<CA , K, D >(
272295 base_path: &str,
273296 ca_certificate: CA,
@@ -325,12 +348,15 @@ pub enum ClientInitError {
325348 /// Missing Hostname
326349 MissingHost,
327350
351+ /// HTTPS requested but TLS features not enabled
352+ TlsNotEnabled,
353+
328354 /// SSL Connection Error
329- #[cfg(any(target_os = " macos" , target_os = " windows" , target_os = " ios" ))]
355+ #[cfg(all(feature = " client-tls " , any(target_os = " macos" , target_os = " windows" , target_os = " ios" ) ))]
330356 SslError(native_tls::Error),
331357
332358 /// SSL Connection Error
333- #[cfg(not (any(target_os = " macos" , target_os = " windows" , target_os = " ios" )))]
359+ #[cfg(all(feature = " client-openssl " , not (any(target_os = " macos" , target_os = " windows" , target_os = " ios" ) )))]
334360 SslError(openssl::error::ErrorStack),
335361}
336362
0 commit comments