diff --git a/Cargo.toml b/Cargo.toml index 3e468adfdf8..da18c6be09e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,6 +104,7 @@ wasmtimer = "0.4.0" hyper = { version = "1.2", default-features = false } hyper-util = "0.1" +hyper-tls = "0.6.0" http-body-util = "0.1" tokio = "1" tokio-util = "0.7" diff --git a/crates/provider/Cargo.toml b/crates/provider/Cargo.toml index c91ca38cd46..0c014ecbeb2 100644 --- a/crates/provider/Cargo.toml +++ b/crates/provider/Cargo.toml @@ -109,6 +109,7 @@ reqwest = [ "alloy-rpc-client/reqwest", ] hyper = ["dep:alloy-transport-http", "dep:url", "alloy-rpc-client/hyper"] +hyper-tls = ["hyper", "alloy-transport-http/hyper-tls"] ws = ["pubsub", "alloy-rpc-client/ws", "alloy-transport-ws"] ipc = ["pubsub", "alloy-rpc-client/ipc", "alloy-transport-ipc"] reqwest-default-tls = ["alloy-transport-http?/reqwest-default-tls"] diff --git a/crates/provider/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 46b419b379a..87c74e21978 100644 --- a/crates/provider/src/provider/trait.rs +++ b/crates/provider/src/provider/trait.rs @@ -1829,6 +1829,18 @@ mod tests { assert_eq!(result.to_string(), "0x"); } + #[tokio::test] + #[cfg(feature = "hyper-tls")] + async fn hyper_https() { + let url = "https://eth-mainnet.alchemyapi.io/v2/jGiK5vwDfC3F4r0bqukm-W2GqgdrxdSr"; + + // With the `hyper` feature enabled .on_builtin builds the provider based on + // `HyperTransport`. + let provider = ProviderBuilder::new().on_builtin(url).await.unwrap(); + + let _num = provider.get_block_number().await.unwrap(); + } + #[tokio::test] async fn test_empty_transactions() { let provider = ProviderBuilder::new().on_anvil(); diff --git a/crates/transport-http/Cargo.toml b/crates/transport-http/Cargo.toml index 7c6b0febc00..78f845041b3 100644 --- a/crates/transport-http/Cargo.toml +++ b/crates/transport-http/Cargo.toml @@ -37,6 +37,7 @@ tracing = { workspace = true, optional = true } http-body-util = { workspace = true, optional = true } hyper = { workspace = true, default-features = false, optional = true } hyper-util = { workspace = true, features = ["full"], optional = true } +hyper-tls = { workspace = true, optional = true } # auth layer alloy-rpc-types-engine = { workspace = true, optional = true } @@ -60,6 +61,7 @@ hyper = [ "dep:tower", "dep:tracing", ] +hyper-tls = ["hyper", "dep:hyper-tls"] jwt-auth = [ "hyper", "dep:alloy-rpc-types-engine", diff --git a/crates/transport-http/src/hyper_transport.rs b/crates/transport-http/src/hyper_transport.rs index 1343aea6b7f..73c17a88fa7 100644 --- a/crates/transport-http/src/hyper_transport.rs +++ b/crates/transport-http/src/hyper_transport.rs @@ -14,6 +14,13 @@ use std::{future::Future, marker::PhantomData, pin::Pin, task}; use tower::Service; use tracing::{debug, debug_span, trace, Instrument}; +#[cfg(feature = "hyper-tls")] +type Hyper = hyper_util::client::legacy::Client< + hyper_tls::HttpsConnector, + http_body_util::Full<::hyper::body::Bytes>, +>; + +#[cfg(not(feature = "hyper-tls"))] type Hyper = hyper_util::client::legacy::Client< hyper_util::client::legacy::connect::HttpConnector, http_body_util::Full<::hyper::body::Bytes>, @@ -49,9 +56,13 @@ impl HyperClient { pub fn new() -> Self { let executor = hyper_util::rt::TokioExecutor::new(); + #[cfg(feature = "hyper-tls")] + let service = hyper_util::client::legacy::Client::builder(executor) + .build(hyper_tls::HttpsConnector::new()); + + #[cfg(not(feature = "hyper-tls"))] let service = hyper_util::client::legacy::Client::builder(executor).build_http::>(); - Self { service, _pd: PhantomData } } }