Skip to content

Commit

Permalink
chore(deps): bump hyper to 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Nov 30, 2023
1 parent 4aff44a commit b36dccb
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 31 deletions.
28 changes: 22 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,38 @@ alloy-networks = { version = "0.1.0", path = "crates/networks" }
alloy-rpc-types = { version = "0.1.0", path = "crates/rpc-types" }
alloy-rpc-client = { version = "0.1.0", path = "crates/rpc-client" }

alloy-primitives = { version = "0.5.1", features = ["serde"] }
alloy-primitives = { version = "0.5.1", default-features = false, features = ["std"] }
alloy-sol-types = { version = "0.5.1", default-features = false, features = ["std"] }
alloy-rlp = "0.3"

# async
async-trait = "0.1.74"
futures = "0.3.29"
futures-util = "0.3.29"
futures-executor = "0.3.29"

http-body-util = "0.1.0"
hyper = { version = "1.0", default-features = false }
hyper-util = "0.1.1"
tokio = "1.33"
tower = { version = "0.4.13", default-features = false, features = ["util"] }

tracing = "0.1.40"
tracing-subscriber = "0.3.18"

tempfile = "3.8"

assert_matches = "1.5"
base64 = "0.21"
bimap = "0.6"
futures = "0.3.29"
hyper = "0.14.27"
itertools = "0.12"
pin-project = "1.1"
rand = "0.8.5"
reqwest = "0.11.18"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_with = "3.4"
home = "0.5"
semver = "1.0"
thiserror = "1.0"
tokio = { version = "1.33", features = ["sync", "macros"] }
tower = { version = "0.4.13", features = ["util"] }
tracing = "0.1.40"
url = "2.4"
6 changes: 5 additions & 1 deletion crates/rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ tracing.workspace = true
alloy-primitives = { workspace = true, optional = true }
alloy-pubsub = { workspace = true, optional = true }
alloy-transport-ws = { workspace = true, optional = true }
hyper = { workspace = true, optional = true }

reqwest = { workspace = true, optional = true }

hyper = { workspace = true, optional = true }
hyper-util = { workspace = true, optional = true }

tokio = { workspace = true, optional = true }
url = { workspace = true, optional = true }

Expand Down
17 changes: 13 additions & 4 deletions crates/rpc-client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,22 @@ impl<L> ClientBuilder<L> {
#[cfg(all(not(target_arch = "wasm32"), feature = "hyper"))]
pub fn hyper_http(self, url: url::Url) -> RpcClient<L::Service>
where
L: Layer<alloy_transport_http::Http<hyper::client::Client<hyper::client::HttpConnector>>>,
L: Layer<
alloy_transport_http::Http<
hyper_util::client::legacy::Client<
hyper_util::client::legacy::connect::HttpConnector,
hyper::body::Bytes,
>,
>,
>,
L::Service: Transport,
{
let transport = alloy_transport_http::Http::new(url);
let is_local = transport.guess_local();
let _ = url;
todo!()
// let transport = alloy_transport_http::Http::new(url);
// let is_local = transport.guess_local();

self.transport(transport, is_local)
// self.transport(transport, is_local)
}

#[cfg(feature = "pubsub")]
Expand Down
6 changes: 4 additions & 2 deletions crates/transport-http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ tower.workspace = true
reqwest = { workspace = true, features = ["serde_json", "json"], optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
hyper = { workspace = true, features = ["full"], 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 }

[features]
default = ["reqwest"]
reqwest = ["dep:reqwest"]
hyper = ["dep:hyper"]
hyper = ["dep:hyper", "dep:hyper-util"]
33 changes: 18 additions & 15 deletions crates/transport-http/src/hyper.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
use crate::Http;
use alloy_json_rpc::{RequestPacket, ResponsePacket};
use alloy_transport::{TransportError, TransportErrorKind, TransportFut};
use http_body_util::{BodyExt, Full};
use hyper::{
body::Bytes,
client::{connect::Connect, Client},
body::{Buf, Bytes},
header,
};
use hyper_util::client::legacy::{connect::Connect, Client};
use std::task;
use tower::Service;

impl<C> Http<Client<C>>
impl<C, B> Http<Client<C, Full<B>>>
where
C: Connect + Clone + Send + Sync + 'static,
B: From<Bytes> + Buf + Send + 'static,
{
/// Make a request.
fn request(&self, req: RequestPacket) -> TransportFut<'static> {
fn request_hyper(&self, req: RequestPacket) -> TransportFut<'static> {
let this = self.clone();
Box::pin(async move {
let ser = req.serialize().map_err(TransportError::ser_err)?;

// convert the Box<RawValue> into a hyper request<B>
let body: Box<str> = ser.into();
let body: Box<[u8]> = body.into();
let body = Full::from(Bytes::from(<Box<[u8]>>::from(<Box<str>>::from(ser))));
let req = hyper::Request::builder()
.method(hyper::Method::POST)
.uri(this.url.as_str())
.header("content-type", "application/json")
.body(hyper::Body::from(Bytes::from(body)))
.header(header::CONTENT_TYPE, header::HeaderValue::from_static("application/json"))
.body(body)
.expect("request parts are valid");

let resp = this.client.request(req).await.map_err(TransportErrorKind::custom)?;

// unpack json from the response body
let body = hyper::body::to_bytes(resp.into_body())
.await
.map_err(TransportErrorKind::custom)?;
let body =
resp.into_body().collect().await.map_err(TransportErrorKind::custom)?.to_bytes();

// Deser a Box<RawValue> from the body. If deser fails, return the
// body as a string in the error. If the body is not UTF8, this will
Expand All @@ -45,9 +46,10 @@ where
}
}

impl<C> Service<RequestPacket> for &Http<Client<C>>
impl<C, B> Service<RequestPacket> for &Http<Client<C, Full<B>>>
where
C: Connect + Clone + Send + Sync + 'static,
B: From<Bytes> + Buf + Send + 'static,
{
type Response = ResponsePacket;
type Error = TransportError;
Expand All @@ -61,13 +63,14 @@ where

#[inline]
fn call(&mut self, req: RequestPacket) -> Self::Future {
self.request(req)
self.request_hyper(req)
}
}

impl<C> Service<RequestPacket> for Http<Client<C>>
impl<C, B> Service<RequestPacket> for Http<Client<C, Full<B>>>
where
C: Connect + Clone + Send + Sync + 'static,
B: From<Bytes> + Buf + Send + 'static,
{
type Response = ResponsePacket;
type Error = TransportError;
Expand All @@ -81,6 +84,6 @@ where

#[inline]
fn call(&mut self, req: RequestPacket) -> Self::Future {
self.request(req)
self.request_hyper(req)
}
}
6 changes: 3 additions & 3 deletions crates/transport-http/src/reqwest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tower::Service;

impl Http<reqwest::Client> {
/// Make a request.
fn request(&self, req: RequestPacket) -> TransportFut<'static> {
fn request_reqwest(&self, req: RequestPacket) -> TransportFut<'static> {
let this = self.clone();
Box::pin(async move {
let resp = this
Expand Down Expand Up @@ -36,7 +36,7 @@ impl Service<RequestPacket> for Http<reqwest::Client> {

#[inline]
fn call(&mut self, req: RequestPacket) -> Self::Future {
self.request(req)
self.request_reqwest(req)
}
}

Expand All @@ -53,6 +53,6 @@ impl Service<RequestPacket> for &Http<reqwest::Client> {

#[inline]
fn call(&mut self, req: RequestPacket) -> Self::Future {
self.request(req)
self.request_reqwest(req)
}
}

0 comments on commit b36dccb

Please sign in to comment.