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 Mar 21, 2024
1 parent f9c90de commit 900179f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 31 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ futures-util = "0.3"
futures-executor = "0.3"
futures-utils-wasm = "0.1"

hyper = "0.14"
hyper = { version = "1.2", default-features = false }
hyper-util = "0.1"
http-body-util = "0.1"
tokio = "1"
tokio-util = "0.7"
tokio-stream = "0.1"
Expand Down
1 change: 0 additions & 1 deletion crates/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ arbitrary = { workspace = true, features = ["derive"], optional = true }

[dev-dependencies]
alloy-signer.workspace = true
# arbitrary
arbitrary = { workspace = true, features = ["derive"] }
k256.workspace = true
tokio = { workspace = true, features = ["macros"] }
Expand Down
6 changes: 5 additions & 1 deletion crates/rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,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 }

url = { workspace = true, optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
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)
}

/// Connect a pubsub transport, producing an [`RpcClient`] with the provided
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,12 +22,14 @@ tower = { workspace = true, optional = 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-default-tls"]
reqwest = ["dep:reqwest", "dep:alloy-json-rpc", "dep:serde_json", "dep:tower"]
hyper = ["dep:hyper", "dep:alloy-json-rpc", "dep:serde_json", "dep:tower"]
hyper = ["dep:hyper", "dep:hyper-util", "dep:alloy-json-rpc", "dep:serde_json", "dep:tower"]
reqwest-default-tls = ["reqwest?/default-tls"]
reqwest-native-tls = ["reqwest?/native-tls"]
reqwest-rustls-tls = ["reqwest?/rustls-tls"]
38 changes: 19 additions & 19 deletions crates/transport-http/src/hyper.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
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)?;

let status = resp.status();

// unpack data from the response body. We do this regardless of
// the status code, as we want to return the error in the body if
// there is one.
let body = hyper::body::to_bytes(resp.into_body())
.await
.map_err(TransportErrorKind::custom)?;
// unpack json from the response body
let body =
resp.into_body().collect().await.map_err(TransportErrorKind::custom)?.to_bytes();

if status != hyper::StatusCode::OK {
return Err(TransportErrorKind::custom_str(&format!(
Expand All @@ -57,9 +55,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 @@ -73,13 +72,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 @@ -93,6 +93,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 @@ -7,7 +7,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 @@ -40,7 +40,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 @@ -57,6 +57,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 900179f

Please sign in to comment.