Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transport): use HttpsConnector in HyperTransport #1899

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this now adds native-tls by default, should this be configurable instead?


# 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
Loading