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/src/provider/trait.rs b/crates/provider/src/provider/trait.rs index 46b419b379a..ae8e4c664b4 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")] + 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..87b74ccacd2 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 } @@ -53,6 +54,7 @@ reqwest = [ ] hyper = [ "dep:hyper", + "dep:hyper-tls", "dep:hyper-util", "dep:http-body-util", "dep:alloy-json-rpc", diff --git a/crates/transport-http/src/hyper_transport.rs b/crates/transport-http/src/hyper_transport.rs index 1343aea6b7f..e0719c4ebbc 100644 --- a/crates/transport-http/src/hyper_transport.rs +++ b/crates/transport-http/src/hyper_transport.rs @@ -15,7 +15,7 @@ use tower::Service; use tracing::{debug, debug_span, trace, Instrument}; type Hyper = hyper_util::client::legacy::Client< - hyper_util::client::legacy::connect::HttpConnector, + hyper_tls::HttpsConnector, http_body_util::Full<::hyper::body::Bytes>, >; @@ -49,8 +49,8 @@ impl HyperClient { pub fn new() -> Self { let executor = hyper_util::rt::TokioExecutor::new(); - let service = - hyper_util::client::legacy::Client::builder(executor).build_http::>(); + let service = hyper_util::client::legacy::Client::builder(executor) + .build(hyper_tls::HttpsConnector::new()); Self { service, _pd: PhantomData } }