diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dd8508a6f..060c8de4d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ The format is based on [Keep a Changelog]. [Keep a Changelog]: http://keepachangelog.com/en/1.0.0/ +## [v0.24.7] + +This is a bug-fix release that fixes the tower::Service implementation to be generic over the HttpBody to work with all middleware layers. +For instance, this makes `tower_http::compression::CompressionLayer` work, which didn't compile before. + +### [Fixed] +- fix(server): make tower::Service impl generic over HttpBody ([#1475](https://github.com/paritytech/jsonrpsee/pull/1475)) + ## [v0.24.6] - 2024-10-07 This is a bug-fix release that fixes that the `ConnectionGuard` was dropped before the future was resolved which, diff --git a/Cargo.toml b/Cargo.toml index 50ef18f4a6..80dd1e519d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ resolver = "2" [workspace.package] authors = ["Parity Technologies ", "Pierre Krieger "] -version = "0.24.6" +version = "0.24.7" edition = "2021" rust-version = "1.74.1" license = "MIT" @@ -31,11 +31,14 @@ keywords = ["jsonrpc", "json", "http", "websocket", "WASM"] readme = "README.md" [workspace.dependencies] -jsonrpsee-types = { path = "types", version = "0.24.6" } -jsonrpsee-core = { path = "core", version = "0.24.6" } -jsonrpsee-server = { path = "server", version = "0.24.6" } -jsonrpsee-ws-client = { path = "client/ws-client", version = "0.24.6" } -jsonrpsee-http-client = { path = "client/http-client", version = "0.24.6" } -jsonrpsee-wasm-client = { path = "client/wasm-client", version = "0.24.6" } -jsonrpsee-client-transport = { path = "client/transport", version = "0.24.6" } -jsonrpsee-proc-macros = { path = "proc-macros", version = "0.24.6" } +jsonrpsee-types = { path = "types", version = "0.24.7" } +jsonrpsee-core = { path = "core", version = "0.24.7" } +jsonrpsee-server = { path = "server", version = "0.24.7" } +jsonrpsee-ws-client = { path = "client/ws-client", version = "0.24.7" } +jsonrpsee-http-client = { path = "client/http-client", version = "0.24.7" } +jsonrpsee-wasm-client = { path = "client/wasm-client", version = "0.24.7" } +jsonrpsee-client-transport = { path = "client/transport", version = "0.24.7" } +jsonrpsee-proc-macros = { path = "proc-macros", version = "0.24.7" } + +tower = "0.4" +tower-http = "0.5" diff --git a/README.md b/README.md index a612b96317..47ca62863f 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ ![MIT](https://img.shields.io/crates/l/jsonrpsee.svg) [![CI](https://github.com/paritytech/jsonrpsee/actions/workflows/ci.yml/badge.svg)](https://github.com/paritytech/jsonrpsee/actions/workflows/ci.yml) [![Benchmarks](https://github.com/paritytech/jsonrpsee/actions/workflows/benchmarks_gitlab.yml/badge.svg)](https://github.com/paritytech/jsonrpsee/actions/workflows/benchmarks_gitlab.yml) -[![dependency status](https://deps.rs/crate/jsonrpsee/0.24.6/status.svg)](https://deps.rs/crate/jsonrpsee/0.24.6) +[![dependency status](https://deps.rs/crate/jsonrpsee/latest/status.svg)](https://deps.rs/crate/jsonrpsee) JSON-RPC library designed for async/await in Rust. diff --git a/client/http-client/Cargo.toml b/client/http-client/Cargo.toml index 216f2d0b3e..daf7968259 100644 --- a/client/http-client/Cargo.toml +++ b/client/http-client/Cargo.toml @@ -29,7 +29,7 @@ serde_json = "1" thiserror = "1" tokio = { version = "1.23.1", features = ["time"] } tracing = "0.1.34" -tower = { version = "0.4.13", features = ["util"] } +tower = { workspace = true, features = ["util"] } url = "2.4.0" [dev-dependencies] diff --git a/examples/Cargo.toml b/examples/Cargo.toml index be6b6dd85f..f3c85fd235 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -19,7 +19,7 @@ tokio = { version = "1.23.1", features = ["full"] } tokio-stream = { version = "0.1", features = ["sync"] } serde_json = { version = "1" } tower-http = { version = "0.5.2", features = ["full"] } -tower = { version = "0.4.13", features = ["full"] } +tower = { workspace = true, features = ["full"] } hyper = "1.3" hyper-util = { version = "0.1.3", features = ["client", "client-legacy"]} console-subscriber = "0.4.0" \ No newline at end of file diff --git a/examples/examples/http_middleware.rs b/examples/examples/http_middleware.rs index 3034037dfa..58f85a8c47 100644 --- a/examples/examples/http_middleware.rs +++ b/examples/examples/http_middleware.rs @@ -40,6 +40,7 @@ use jsonrpsee::rpc_params; use std::iter::once; use std::net::SocketAddr; use std::time::Duration; +use tower_http::compression::CompressionLayer; use tower_http::cors::CorsLayer; use tower_http::sensitive_headers::SetSensitiveRequestHeadersLayer; use tower_http::trace::{DefaultMakeSpan, DefaultOnResponse, TraceLayer}; @@ -107,6 +108,7 @@ async fn run_server() -> anyhow::Result { // Mark the `Authorization` request header as sensitive so it doesn't show in logs .layer(SetSensitiveRequestHeadersLayer::new(once(hyper::header::AUTHORIZATION))) .layer(cors) + .layer(CompressionLayer::new()) .timeout(Duration::from_secs(2)); let server = diff --git a/examples/examples/jsonrpsee_as_service.rs b/examples/examples/jsonrpsee_as_service.rs index ae07e79b17..7b098d1a0a 100644 --- a/examples/examples/jsonrpsee_as_service.rs +++ b/examples/examples/jsonrpsee_as_service.rs @@ -48,6 +48,7 @@ use jsonrpsee::ws_client::{HeaderValue, WsClientBuilder}; use jsonrpsee::{MethodResponse, Methods}; use tokio::net::TcpListener; use tower::Service; +use tower_http::compression::CompressionLayer; use tower_http::cors::CorsLayer; use tracing_subscriber::util::SubscriberInitExt; @@ -202,6 +203,7 @@ async fn run_server(metrics: Metrics) -> anyhow::Result { let transport_label = if is_websocket { "ws" } else { "http" }; let PerConnection { methods, stop_handle, metrics, svc_builder } = per_conn2.clone(); + let http_middleware = tower::ServiceBuilder::new().layer(CompressionLayer::new()); // NOTE, the rpc middleware must be initialized here to be able to created once per connection // with data from the connection such as the headers in this example let headers = req.headers().clone(); @@ -209,7 +211,10 @@ async fn run_server(metrics: Metrics) -> anyhow::Result { AuthorizationMiddleware { inner: service, headers: headers.clone(), transport_label } }); - let mut svc = svc_builder.set_rpc_middleware(rpc_middleware).build(methods, stop_handle); + let mut svc = svc_builder + .set_http_middleware(http_middleware) + .set_rpc_middleware(rpc_middleware) + .build(methods, stop_handle); if is_websocket { // Utilize the session close future to know when the actual WebSocket diff --git a/proc-macros/Cargo.toml b/proc-macros/Cargo.toml index 8e44734e2c..bfd1aaf4c1 100644 --- a/proc-macros/Cargo.toml +++ b/proc-macros/Cargo.toml @@ -33,4 +33,4 @@ serde_json = "1" serde = "1" trybuild = "1.0.97" tokio = { version = "1.23.1", features = ["rt", "macros"] } -tower = "0.4" +tower = { workspace = true } diff --git a/server/Cargo.toml b/server/Cargo.toml index f244393be7..1cbd6c9e6c 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -29,7 +29,7 @@ hyper-util = { version = "0.1", features = ["tokio", "service", "tokio", "server http = "1" http-body = "1" http-body-util = "0.1.0" -tower = { version = "0.4.13", features = ["util"] } +tower = { workspace = true, features = ["util"] } thiserror = "1" route-recognizer = "0.3.1" pin-project = "1.1.3" @@ -37,5 +37,5 @@ pin-project = "1.1.3" [dev-dependencies] jsonrpsee-test-utils = { path = "../test-utils" } tracing-subscriber = { version = "0.3.3", features = ["env-filter"] } -tower = { version = "0.4.13", features = ["timeout"] } +tower = { workspace = true, features = ["timeout"] } socket2 = "0.5.1" diff --git a/server/src/server.rs b/server/src/server.rs index 5a89a6d131..6ec34eb262 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -970,20 +970,20 @@ impl TowerService } } -impl Service> for TowerService +impl Service> for TowerService where RpcMiddleware: for<'a> tower::Layer + Clone, >::Service: Send + Sync + 'static, for<'a> >::Service: RpcServiceT<'a>, HttpMiddleware: Layer> + Send + 'static, >>::Service: - Send + Service, Response = HttpResponse, Error = Box<(dyn StdError + Send + Sync + 'static)>>, - <>>::Service as Service>>::Future: + Send + Service, Response = HttpResponse, Error = Box<(dyn StdError + Send + Sync + 'static)>>, + <>>::Service as Service>>::Future: Send + 'static, - Body: http_body::Body + Send + 'static, - Body::Error: Into, + RequestBody: http_body::Body + Send + 'static, + RequestBody::Error: Into, { - type Response = HttpResponse; + type Response = HttpResponse; type Error = BoxError; type Future = Pin> + Send>>; @@ -991,7 +991,7 @@ where Poll::Ready(Ok(())) } - fn call(&mut self, request: HttpRequest) -> Self::Future { + fn call(&mut self, request: HttpRequest) -> Self::Future { Box::pin(self.http_middleware.service(self.rpc_middleware.clone()).call(request)) } } diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 75be704047..330df1fc04 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -22,8 +22,8 @@ serde_json = "1" tokio = { version = "1.23.1", features = ["full"] } tokio-stream = "0.1" tokio-util = { version = "0.7", features = ["compat"]} -tower = { version = "0.4.13", features = ["full"] } -tower-http = { version = "0.5.2", features = ["full"] } +tower = { workspace = true, features = ["full"] } +tower-http = { workspace = true, features = ["full"] } tracing = "0.1.34" tracing-subscriber = { version = "0.3.3", features = ["env-filter"] } pin-project = "1"