Skip to content

Commit

Permalink
fix(transport): use HttpsConnector in HyperTransport
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-atreya committed Jan 8, 2025
1 parent d809bd7 commit 833afad
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 12 additions & 0 deletions crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions crates/transport-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -53,6 +54,7 @@ reqwest = [
]
hyper = [
"dep:hyper",
"dep:hyper-tls",
"dep:hyper-util",
"dep:http-body-util",
"dep:alloy-json-rpc",
Expand Down
6 changes: 3 additions & 3 deletions crates/transport-http/src/hyper_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<hyper_util::client::legacy::connect::HttpConnector>,
http_body_util::Full<::hyper::body::Bytes>,
>;

Expand Down Expand Up @@ -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::<Full<Bytes>>();
let service = hyper_util::client::legacy::Client::builder(executor)
.build(hyper_tls::HttpsConnector::new());

Self { service, _pd: PhantomData }
}
Expand Down

0 comments on commit 833afad

Please sign in to comment.