@@ -121,11 +121,8 @@ 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- ))]
128- Https(hyper_util::client::legacy::Client<HttpsConnector, BoxBody<Bytes, Infallible>>),
124+ #[cfg(feature = "client-tls")]
125+ Https(hyper_util::client::legacy::Client<hyper_tls::HttpsConnector<hyper_util::client::legacy::connect::HttpConnector>, BoxBody<Bytes, Infallible>>),
129126}
130127
131128impl Service<Request<BoxBody<Bytes, Infallible>>> for HyperClient {
@@ -136,10 +133,7 @@ impl Service<Request<BoxBody<Bytes, Infallible>>> for HyperClient {
136133 fn call(&self, req: Request<BoxBody<Bytes, Infallible>>) -> Self::Future {
137134 match self {
138135 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- ))]
136+ #[cfg(feature = "client-tls")]
143137 HyperClient::Https(client) => client.request(req),
144138 }
145139 }
@@ -166,20 +160,15 @@ impl<C> Client<DropContextService<HyperClient, C>, C> where
166160 " http" => {
167161 HyperClient::Http(hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new()).build(connector.build()))
168162 } ,
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- ))]
163+ #[cfg(feature = "client-tls")]
173164 "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))
165+ // Build native-tls connector directly to avoid ambiguity with OpenSSL
166+ let mut http_connector = hyper_util::client::legacy::connect::HttpConnector::new();
167+ http_connector.enforce_http(false );
168+ let https_connector = hyper_tls::HttpsConnector::new_with_connector(http_connector);
169+ HyperClient::Https(hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new()).build(https_connector))
178170 } ,
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- )))]
171+ #[cfg(not(feature = "client-tls"))]
183172 "https" => {
184173 return Err(ClientInitError::TlsNotEnabled);
185174 } ,
@@ -225,21 +214,12 @@ impl<C> Client<
225214 }
226215}
227216
228- #[cfg(all(feature = "client-tls", any(target_os = "macos", target_os = "windows", target_os = "ios")))]
229- type HttpsConnector = hyper_tls::HttpsConnector<hyper _util::client::legacy::connect::HttpConnector >;
230-
231- #[cfg(all(feature = "client-openssl", not(any(target_os = "macos", target_os = "windows", target_os = "ios"))))]
232- type HttpsConnector = hyper_openssl::client::legacy::HttpsConnector<hyper _util::client::legacy::connect::HttpConnector >;
233-
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- ))]
217+ #[cfg(feature = "client-tls")]
238218impl<C > Client<
239219 DropContextService<
240220 hyper_util::service::TowerToHyperService<
241221 hyper_util::client::legacy::Client<
242- HttpsConnector,
222+ hyper_tls:: HttpsConnector< hyper _util::client::legacy::connect::HttpConnector > ,
243223 BoxBody<Bytes , Infallible >
244224 >
245225 >,
@@ -252,62 +232,13 @@ impl<C> Client<
252232 /// Create a client with a TLS connection to the server
253233 ///
254234 /// # Arguments
255- /// * `base_path` - base path of the client API, i.e. " <http ://www.my-api-implementation.com>"
235+ /// * `base_path` - base path of the client API, i.e. " <https ://www.my-api-implementation.com>"
256236 pub fn try_new_https(base_path: &str) -> Result< Self, ClientInitError>
257237 {
258- let https_connector = Connector::builder()
259- .https()
260- .build()
261- .map_err(ClientInitError::SslError)?;
262- Self::try_new_with_connector(base_path, Some(" https" ), https_connector)
263- }
264-
265- /// Create a client with a TLS connection to the server using a pinned certificate
266- ///
267- /// # Arguments
268- /// * `base_path` - base path of the client API, i.e. "<http: //www.my-api-implementation.com >"
269- /// * `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"))))]
271- pub fn try_new_https_pinned<CA >(
272- base_path: &str,
273- ca_certificate: CA,
274- ) -> Result<Self , ClientInitError >
275- where
276- CA: AsRef<Path >,
277- {
278- let https_connector = Connector::builder()
279- .https()
280- .pin_server_certificate(ca_certificate)
281- .build()
282- .map_err(ClientInitError::SslError)?;
283- Self::try_new_with_connector(base_path, Some(" https" ), https_connector)
284- }
285-
286- /// Create a client with a mutually authenticated TLS connection to the server.
287- ///
288- /// # Arguments
289- /// * `base_path` - base path of the client API, i.e. "<http: //www.my-api-implementation.com >"
290- /// * `ca_certificate` - Path to CA certificate used to authenticate the server
291- /// * `client_key` - Path to the client private key
292- /// * `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"))))]
294- pub fn try_new_https_mutual<CA , K, D >(
295- base_path: &str,
296- ca_certificate: CA,
297- client_key: K,
298- client_certificate: D,
299- ) -> Result<Self , ClientInitError >
300- where
301- CA: AsRef<Path >,
302- K: AsRef<Path >,
303- D: AsRef<Path >,
304- {
305- let https_connector = Connector::builder()
306- .https()
307- .pin_server_certificate(ca_certificate)
308- .client_authentication(client_key, client_certificate)
309- .build()
310- .map_err(ClientInitError::SslError)?;
238+ // Build native-tls connector directly
239+ let mut http_connector = hyper_util::client::legacy::connect::HttpConnector::new();
240+ http_connector.enforce_http(false );
241+ let https_connector = hyper_tls::HttpsConnector::new_with_connector(http_connector);
311242 Self::try_new_with_connector(base_path, Some(" https" ), https_connector)
312243 }
313244}
@@ -352,12 +283,8 @@ pub enum ClientInitError {
352283 TlsNotEnabled,
353284
354285 /// SSL Connection Error
355- #[cfg(all( feature = " client-tls" , any(target_os = " macos " , target_os = " windows " , target_os = " ios " )) )]
286+ #[cfg(feature = " client-tls" )]
356287 SslError(native_tls::Error),
357-
358- /// SSL Connection Error
359- #[cfg(all(feature = " client-openssl" , not (any(target_os = " macos" , target_os = " windows" , target_os = " ios" ))))]
360- SslError(openssl::error::ErrorStack),
361288}
362289
363290impl From<hyper::http::uri::InvalidUri > for ClientInitError {
0 commit comments