Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ heck = "0.5.0"
http = "1"
http-body = "1"
http-body-util = "0.1.0"
hyper = "1.5"
cfg_aliases = "0.2"
log = "0.4"
hyper = "1.8"
hyper-rustls = { version = "0.27", default-features = false }
hyper-util = "0.1"
mio = { version = "1.2.0", default-features = false }
parking_lot = "0.12"
pin-project = "1.1.3"
proc-macro-crate = "3"
Expand All @@ -67,19 +70,21 @@ rustc-hash = "2"
rustls = { version = "0.23", default-features = false }
rustls-pki-types = "1"
rustls-platform-verifier = "0.5"
rustls-rustcrypto = "0.0.2-alpha"
serde = { version = "1", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.142", default-features = false, features = ["alloc", "raw_value"] }
soketto = "0.8.1"
syn = { version = "2", default-features = false }
thiserror = "2"
tokio = "1.42"
tokio = { version = "1.51", default-features = false }
tokio-rustls = { version = "0.26", default-features = false }
tokio-stream = "0.1.7"
tokio-util = "0.7"
tower = "0.5"
tower-http = "0.6"
tracing = "0.1.34"
url = "2.4"
webpki-roots = "0.26"
wasm-bindgen-futures = "0.4.19"

# Dev dependencies
Expand All @@ -89,7 +94,7 @@ criterion = { version = "0.5", features = ["async_tokio", "html_reports"] }
fast-socks5 = "0.10"
futures = { version = "0.3.14", default-features = false, features = ["std"] }
pprof = { version = "0.15", features = ["flamegraph", "criterion"] }
socket2 = "0.6.0"
socket2 = "0.6.3"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
trybuild = "1.0.97"

Expand Down
20 changes: 16 additions & 4 deletions client/http-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@ publish = true
[lints]
workspace = true

[build-dependencies]
cfg_aliases = { workspace = true }

[dependencies]
base64 = { workspace = true }
hyper = { workspace = true, features = ["client", "http1", "http2"] }
hyper-rustls = { workspace = true, features = ["http1", "http2", "tls12", "logging", "ring"], optional = true }
hyper-rustls = { workspace = true, features = ["http1", "http2", "tls12", "logging"], optional = true }
hyper-util = { workspace = true, features = ["client", "client-legacy", "tokio", "http1", "http2"] }
http-body = { workspace = true }
log = { workspace = true }
jsonrpsee-types = { workspace = true }
jsonrpsee-core = { workspace = true, features = ["client", "http-helpers"] }
rustls = { workspace = true, optional = true, features = ["logging", "std", "tls12", "ring"] }
rustls = { workspace = true, optional = true, features = ["logging", "std", "tls12"] }
rustls-platform-verifier = { workspace = true, optional = true }
rustls-rustcrypto = { workspace = true, optional = true }
webpki-roots = { workspace = true, optional = true }
serde = { workspace = true, features = ["alloc"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
Expand All @@ -36,11 +42,17 @@ url = { workspace = true }
[dev-dependencies]
tracing-subscriber = { workspace = true }
jsonrpsee-test-utils = { path = "../../test-utils" }
tokio = { workspace = true, features = ["net", "rt-multi-thread", "macros"] }
tokio = { workspace = true, features = ["macros"] }

[target.'cfg(not(all(target_os = "wasi", target_env = "p2")))'.dev-dependencies]
tokio = { workspace = true, features = ["net", "rt-multi-thread"] }

[features]
default = ["tls"]
tls = ["hyper-rustls", "rustls", "rustls-platform-verifier"]
tls = ["hyper-rustls", "hyper-rustls/ring", "rustls", "rustls/ring", "rustls-platform-verifier"]
# Note: rustls-platform-verifier is used on native targets (ConfigVerifierExt) but compiled-unused
# on wasip2 where webpki_roots provides cert verification instead.
tls-rustcrypto = ["hyper-rustls", "rustls", "rustls-rustcrypto", "rustls-platform-verifier", "webpki-roots"]

[package.metadata.docs.rs]
all-features = true
Expand Down
7 changes: 7 additions & 0 deletions client/http-client/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Build script for jsonrpsee-http-client: sets up cfg aliases.

fn main() {
cfg_aliases::cfg_aliases! {
wasip2: { all(target_os = "wasi", target_env = "p2") },
}
}
16 changes: 8 additions & 8 deletions client/http-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use tokio::sync::Semaphore;
use tower::layer::util::Identity;
use tower::{Layer, Service};

#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustcrypto"))]
use crate::{CertificateStore, CustomCertStore};

type Logger = tower::layer::util::Stack<RpcLoggerLayer, tower::layer::util::Identity>;
Expand Down Expand Up @@ -82,7 +82,7 @@ pub struct HttpClientBuilder<HttpMiddleware = Identity, RpcMiddleware = Logger>
max_request_size: u32,
max_response_size: u32,
request_timeout: Duration,
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustcrypto"))]
certificate_store: CertificateStore,
id_kind: IdKind,
headers: HeaderMap,
Expand Down Expand Up @@ -185,7 +185,7 @@ impl<HttpMiddleware, RpcMiddleware> HttpClientBuilder<HttpMiddleware, RpcMiddlew
/// // client builder with disabled certificate verification.
/// let client_builder = HttpClientBuilder::new().with_custom_cert_store(tls_cfg);
/// ```
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustcrypto"))]
pub fn with_custom_cert_store(mut self, cfg: CustomCertStore) -> Self {
self.certificate_store = CertificateStore::Custom(cfg);
self
Expand Down Expand Up @@ -234,7 +234,7 @@ impl<HttpMiddleware, RpcMiddleware> HttpClientBuilder<HttpMiddleware, RpcMiddlew
/// Set the RPC middleware.
pub fn set_rpc_middleware<T>(self, rpc_builder: RpcServiceBuilder<T>) -> HttpClientBuilder<HttpMiddleware, T> {
HttpClientBuilder {
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustcrypto"))]
certificate_store: self.certificate_store,
id_kind: self.id_kind,
headers: self.headers,
Expand All @@ -257,7 +257,7 @@ impl<HttpMiddleware, RpcMiddleware> HttpClientBuilder<HttpMiddleware, RpcMiddlew
service_builder: tower::ServiceBuilder<T>,
) -> HttpClientBuilder<T, RpcMiddleware> {
HttpClientBuilder {
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustcrypto"))]
certificate_store: self.certificate_store,
id_kind: self.id_kind,
headers: self.headers,
Expand Down Expand Up @@ -291,7 +291,7 @@ where
max_request_size,
max_response_size,
request_timeout,
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustcrypto"))]
certificate_store,
id_kind,
headers,
Expand All @@ -313,7 +313,7 @@ where
keep_alive_duration,
keep_alive_interval,
keep_alive_retries,
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustcrypto"))]
certificate_store,
}
.build(target)
Expand All @@ -338,7 +338,7 @@ impl Default for HttpClientBuilder {
max_request_size: TEN_MB_SIZE_BYTES,
max_response_size: TEN_MB_SIZE_BYTES,
request_timeout: Duration::from_secs(60),
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustcrypto"))]
certificate_store: CertificateStore::Native,
id_kind: IdKind::Number,
headers: HeaderMap::new(),
Expand Down
15 changes: 13 additions & 2 deletions client/http-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![cfg_attr(docsrs, feature(doc_cfg))]

// These crates are only used behind wasip2 cfg gates, suppress unused warnings on other targets.
#[cfg(not(wasip2))]
use log as _;
#[cfg(all(feature = "tls-rustcrypto", not(wasip2)))]
use webpki_roots as _;

// rustls_platform_verifier is used on native targets (ConfigVerifierExt) but not on wasip2,
// where we use webpki_roots instead. Suppress the unused dependency warning for wasip2.
#[cfg(wasip2)]
use rustls_platform_verifier as _;

mod client;
mod rpc_service;

Expand Down Expand Up @@ -62,10 +73,10 @@ pub use jsonrpsee_core::middleware::{RpcServiceBuilder, RpcServiceT};
pub use transport::{HttpBackend, HttpTransportClient};

/// Custom TLS configuration.
#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustcrypto"))]
pub type CustomCertStore = rustls::ClientConfig;

#[cfg(feature = "tls")]
#[cfg(any(feature = "tls", feature = "tls-rustcrypto"))]
// rustls needs the concrete `ClientConfig` type so we can't Box it here.
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug)]
Expand Down
6 changes: 3 additions & 3 deletions client/http-client/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ async fn batch_request_out_of_order_response() {
assert_eq!(response, vec!["hello".to_string(), "goodbye".to_string(), "here's your swag".to_string()]);
}

async fn run_batch_request_with_response<T: Send + DeserializeOwned + std::fmt::Debug + Clone + 'static>(
batch: BatchRequestBuilder<'_>,
async fn run_batch_request_with_response<'a, T: Send + DeserializeOwned + std::fmt::Debug + Clone + 'static>(
batch: BatchRequestBuilder<'a>,
response: String,
) -> Result<BatchResponse<T>, ClientError> {
) -> Result<BatchResponse<'a, T>, ClientError> {
let server_addr = http_server_with_hardcoded_response(response).with_default_timeout().await.unwrap();
let uri = format!("http://{server_addr}");
let client = HttpClientBuilder::default().build(&uri).unwrap();
Expand Down
Loading