Commit 944c3d7f authored by Niklas Adolfsson's avatar Niklas Adolfsson
Browse files

Merge remote-tracking branch 'origin/master' into HEAD

parents 7b4d14d4 21e557d2
Pipeline #206656 passed with stages
in 5 minutes
......@@ -4,7 +4,52 @@ The format is based on [Keep a Changelog].
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/
## [Unreleased]
## [v0.15.1] - 2022-07-29
This release fixes some incorrect tracing spans.
### [Fixed]
- [Bug Fix] - Incorrect trace caused by use of Span::enter in asynchronous code [#835](https://github.com/paritytech/jsonrpsee/pull/835)
## [v0.15.0] - 2022-07-20
v0.15.0 is a breaking release. The main changes are:
- It's now possible to apply resource limits to subscriptions as well as regular calls.
- We now allow trait bounds to be overridden in the proc macros. See `examples/examples/proc_macro_bounds.rs` for examples.
- We've tidied up the subscription API, removing the `PendingSink` concept (you can still manually accept or reject a sink, but otherwise it'll be accepted automatically if you send a message down it) ([#799](https://github.com/paritytech/jsonrpsee/pull/799)).
- Our logging `Middleware` trait has been split into `HttpMiddleware` and `WsMiddleware` to better capture the differences between the two. if you use custom middleware, you'll need to implement one or the other trait on it depending on your used transport method ([#793](https://github.com/paritytech/jsonrpsee/pull/793)). We also provide params and the method type to middleware calls now, too ([#820](https://github.com/paritytech/jsonrpsee/pull/820)).
- We've consistified the API for setting headers across HTTP and WS clients ([#799](https://github.com/paritytech/jsonrpsee/pull/814)).
Here's the full list of changes:
### [Fixed]
- Fix client generation with param_kind = map [#805](https://github.com/paritytech/jsonrpsee/pull/805)
- ws-server: Handle soketto::Incoming::Closed frames [#815](https://github.com/paritytech/jsonrpsee/pull/815)
- fix(ws server): reply HTTP 403 on all failed conns [#819](https://github.com/paritytech/jsonrpsee/pull/819)
- fix clippy [#817](https://github.com/paritytech/jsonrpsee/pull/817)
### [Added]
- Add resource limiting for Subscriptions [#786](https://github.com/paritytech/jsonrpsee/pull/786)
- feat(logging): add tracing span per JSON-RPC call [#722](https://github.com/paritytech/jsonrpsee/pull/722)
- feat(clients): add explicit unsubscribe API [#789](https://github.com/paritytech/jsonrpsee/pull/789)
- Allow trait bounds to be overridden in macro [#808](https://github.com/paritytech/jsonrpsee/pull/808)
### [Changed]
- Point to a new v1.0 milestone in the README.md [#801](https://github.com/paritytech/jsonrpsee/pull/801)
- chore(deps): upgrade tracing v0.1.34 [#800](https://github.com/paritytech/jsonrpsee/pull/800)
- Replace cargo-nextest with cargo-test for running tests [#802](https://github.com/paritytech/jsonrpsee/pull/802)
- Remove deny_unknown_fields from Request and Response [#803](https://github.com/paritytech/jsonrpsee/pull/803)
- substrate-subxt -> subxt [#807](https://github.com/paritytech/jsonrpsee/pull/807)
- chore(deps): update pprof requirement from 0.9 to 0.10 [#810](https://github.com/paritytech/jsonrpsee/pull/810)
- Return error from subscription callbacks [#799](https://github.com/paritytech/jsonrpsee/pull/799)
- middleware refactoring [#793](https://github.com/paritytech/jsonrpsee/pull/793)
- feat(middleware): expose type of the method call [#820](https://github.com/paritytech/jsonrpsee/pull/820)
- Uniform API for custom headers between clients [#814](https://github.com/paritytech/jsonrpsee/pull/814)
- Update links to client directories. [#822](https://github.com/paritytech/jsonrpsee/pull/822)
## [v0.14.0] - 2022-06-14
......
......@@ -9,10 +9,10 @@ Designed to be the successor to [ParityTech's JSONRPC crate](https://github.com/
Support `WebSocket` and `HTTP` transports for both client and server.
## Sub-projects
- [jsonrpsee-http-client](./http-client) [![crates.io][http-client-image]][http-client-url]
- [jsonrpsee-http-client](./client/http-client) [![crates.io][http-client-image]][http-client-url]
- [jsonrpsee-http-server](./http-server) [![crates.io][http-server-image]][http-server-url]
- [jsonrpsee-proc-macros](./proc-macros) [![crates.io][proc-macros-image]][proc-macros-url]
- [jsonrpsee-ws-client](./ws-client) [![crates.io][ws-client-image]][ws-client-url]
- [jsonrpsee-ws-client](./client/ws-client) [![crates.io][ws-client-image]][ws-client-url]
- [jsonrpsee-ws-server](./ws-server) [![crates.io][ws-server-image]][ws-server-url]
[http-client-image]: https://img.shields.io/crates/v/jsonrpsee-http-client.svg
......@@ -32,7 +32,7 @@ Support `WebSocket` and `HTTP` transports for both client and server.
- [WebSocket](./examples/examples/ws.rs)
- [WebSocket pubsub](./examples/examples/ws_pubsub_broadcast.rs)
- [API generation with proc macro](./examples/examples/proc_macro.rs)
- [Middleware](./examples/examples/multi_middleware.rs)
- [Logger](./examples/examples/multi_logger.rs)
- [CORS server](./examples/examples/cors_server.rs)
- [Core client](./examples/examples/core_client.rs)
......
# How to release `jsonrpsee`
# Release Checklist
These steps assume that you've checked out the Jsonrpsee repository and are in the root directory of it.
We also assume that ongoing work done is being merged directly to the `master` branch.
1. Ensure that everything you'd like to see released is on the `master` branch.
2. Create a release branch off `master`, for example `chore-release-v0.15.0`. Decide how far the version needs to be bumped based
on the changes to date. If unsure what to bump the version to (e.g. is it a major, minor or patch release), check with the
Parity Tools team.
3. Bump the crate versions in `Cargo.toml` to whatever was decided in step 2. The easiest approach is to search and replace, checking
that you didn't replace any other crate versions along the way.
4. Update `CHANGELOG.md` to reflect the difference between this release and the last. If you're unsure of
what to add, check with the Tools team. See the `CHANGELOG.md` file for details of the format it follows.
First, if there have been any significant changes, add a description of those changes to the top of the
changelog entry for this release. This will help people to understand the impact of the change and what they need to do
to adopt it.
Next, you can use the following script to generate the merged PRs between releases:
```
./scripts/generate_changelog.sh
```
Ensure that the script picked the latest published release tag (e.g. if releasing `v0.15.0`, the script should
provide something like `[+] Latest release tag: v0.14.0` ). Then group the PRs into "Fixed", "Added" and "Changed" sections,
and make any other adjustments that you feel are necessary for clarity.
5. Commit any of the above changes to the release branch and open a PR in GitHub with a base of `master`. Name the branch something
like `chore(release): v0.15.0`.
6. Once the branch has been reviewed and passes CI, merge it.
7. Now, we're ready to publish the release to crates.io. Run `./scripts/publish.sh` to publish all crates in the correct order.
8. If the release was successful, tag the commit that we released in the `master` branch with the
version that we just released, for example:
```
git tag -s v0.15.0 # use the version number you've just published to crates.io, not this
git push --tags
```
Once this is pushed, go along to [the releases page on GitHub](https://github.com/paritytech/jsonrpsee/releases)
and draft a new release which points to the tag you just pushed to `master` above. Copy the changelog comments
for the current release into the release description.
1. Bump the version of all crates
1. Run all tests
1. In the `CHANGELOG.md` file, move everything under "Unreleased" to a new section named `## [vx.y.z] – YYYY-MM-DD`
1. Publish: `./scripts/publish.sh`
1. Once published, make sure to "create a release" for the pushed tag on github.
[package]
name = "jsonrpsee-benchmarks"
version = "0.14.0"
version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Benchmarks for jsonrpsee"
edition = "2021"
......
[package]
name = "jsonrpsee-http-client"
version = "0.14.0"
version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "HTTP client for JSON-RPC"
edition = "2021"
......@@ -14,8 +14,8 @@ async-trait = "0.1"
rustc-hash = "1"
hyper = { version = "0.14.10", features = ["client", "http1", "http2", "tcp"] }
hyper-rustls = { version = "0.23", optional = true }
jsonrpsee-types = { path = "../../types", version = "0.14.0" }
jsonrpsee-core = { path = "../../core", version = "0.14.0", features = ["client", "http-helpers"] }
jsonrpsee-types = { path = "../../types", version = "0.15.1" }
jsonrpsee-core = { path = "../../core", version = "0.15.1", features = ["client", "http-helpers"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = "1.0"
thiserror = "1.0"
......
......@@ -168,11 +168,10 @@ pub struct HttpClient {
impl ClientT for HttpClient {
async fn notification<'a>(&self, method: &'a str, params: Option<ParamsSer<'a>>) -> Result<(), Error> {
let trace = RpcTracing::notification(method);
let _enter = trace.span().enter();
async {
let notif = serde_json::to_string(&NotificationSer::new(method, params)).map_err(Error::ParseError)?;
let fut = self.transport.send(notif).in_current_span();
let fut = self.transport.send(notif);
match tokio::time::timeout(self.request_timeout, fut).await {
Ok(Ok(ok)) => Ok(ok),
......@@ -180,6 +179,9 @@ impl ClientT for HttpClient {
Ok(Err(e)) => Err(Error::Transport(e.into())),
}
}
.instrument(trace.into_span())
.await
}
/// Perform a request towards the server.
async fn request<'a, R>(&self, method: &'a str, params: Option<ParamsSer<'a>>) -> Result<R, Error>
......@@ -190,11 +192,11 @@ impl ClientT for HttpClient {
let id = guard.inner();
let request = RequestSer::new(&id, method, params);
let trace = RpcTracing::method_call(method);
let _enter = trace.span().enter();
async {
let raw = serde_json::to_string(&request).map_err(Error::ParseError)?;
let fut = self.transport.send_and_read_body(raw).in_current_span();
let fut = self.transport.send_and_read_body(raw);
let body = match tokio::time::timeout(self.request_timeout, fut).await {
Ok(Ok(body)) => body,
Err(_e) => {
......@@ -219,6 +221,9 @@ impl ClientT for HttpClient {
Err(Error::InvalidRequestId)
}
}
.instrument(trace.into_span())
.await
}
async fn batch_request<'a, R>(&self, batch: Vec<(&'a str, Option<ParamsSer<'a>>)>) -> Result<Vec<R>, Error>
where
......@@ -227,8 +232,8 @@ impl ClientT for HttpClient {
let guard = self.id_manager.next_request_ids(batch.len())?;
let ids: Vec<Id> = guard.inner();
let trace = RpcTracing::batch();
let _enter = trace.span().enter();
async {
let mut batch_request = Vec::with_capacity(batch.len());
// NOTE(niklasad1): `ID` is not necessarily monotonically increasing.
let mut ordered_requests = Vec::with_capacity(batch.len());
......@@ -240,10 +245,8 @@ impl ClientT for HttpClient {
request_set.insert(&ids[pos], pos);
}
let fut = self
.transport
.send_and_read_body(serde_json::to_string(&batch_request).map_err(Error::ParseError)?)
.in_current_span();
let fut =
self.transport.send_and_read_body(serde_json::to_string(&batch_request).map_err(Error::ParseError)?);
let body = match tokio::time::timeout(self.request_timeout, fut).await {
Ok(Ok(body)) => body,
......@@ -268,6 +271,9 @@ impl ClientT for HttpClient {
}
Ok(responses)
}
.instrument(trace.into_span())
.await
}
}
#[async_trait]
......
[package]
name = "jsonrpsee-client-transport"
version = "0.14.0"
version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "WebSocket client for JSON-RPC"
edition = "2021"
......@@ -10,8 +10,8 @@ homepage = "https://github.com/paritytech/jsonrpsee"
documentation = "https://docs.rs/jsonrpsee-ws-client"
[dependencies]
jsonrpsee-types = { path = "../../types", version = "0.14.0", optional = true }
jsonrpsee-core = { path = "../../core", version = "0.14.0", features = ["client"] }
jsonrpsee-types = { path = "../../types", version = "0.15.1", optional = true }
jsonrpsee-core = { path = "../../core", version = "0.15.1", features = ["client"] }
tracing = "0.1.34"
# optional
......
[package]
name = "jsonrpsee-wasm-client"
version = "0.14.0"
version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "WASM client for JSON-RPC"
edition = "2021"
......@@ -10,9 +10,9 @@ homepage = "https://github.com/paritytech/jsonrpsee"
documentation = "https://docs.rs/jsonrpsee-ws-client"
[dependencies]
jsonrpsee-types = { path = "../../types", version = "0.14.0" }
jsonrpsee-client-transport = { path = "../transport", version = "0.14.0", features = ["web"] }
jsonrpsee-core = { path = "../../core", version = "0.14.0", features = ["async-wasm-client"] }
jsonrpsee-types = { path = "../../types", version = "0.15.1" }
jsonrpsee-client-transport = { path = "../transport", version = "0.15.1", features = ["web"] }
jsonrpsee-core = { path = "../../core", version = "0.15.1", features = ["async-wasm-client"] }
[dev-dependencies]
tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
......
[package]
name = "jsonrpsee-ws-client"
version = "0.14.0"
version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>", "Pierre Krieger <pierre.krieger1708@gmail.com>"]
description = "WebSocket client for JSON-RPC"
edition = "2021"
......@@ -10,9 +10,9 @@ homepage = "https://github.com/paritytech/jsonrpsee"
documentation = "https://docs.rs/jsonrpsee-ws-client"
[dependencies]
jsonrpsee-types = { path = "../../types", version = "0.14.0" }
jsonrpsee-client-transport = { path = "../transport", version = "0.14.0", features = ["ws"] }
jsonrpsee-core = { path = "../../core", version = "0.14.0", features = ["async-client"] }
jsonrpsee-types = { path = "../../types", version = "0.15.1" }
jsonrpsee-client-transport = { path = "../transport", version = "0.15.1", features = ["ws"] }
jsonrpsee-core = { path = "../../core", version = "0.15.1", features = ["async-client"] }
http = "0.2.0"
[dev-dependencies]
......
[package]
name = "jsonrpsee-core"
version = "0.14.0"
version = "0.15.1"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Utilities for jsonrpsee"
edition = "2021"
......@@ -11,7 +11,7 @@ anyhow = "1"
async-trait = "0.1"
beef = { version = "0.5.1", features = ["impl_serde"] }
futures-channel = "0.3.14"
jsonrpsee-types = { path = "../types", version = "0.14.0" }
jsonrpsee-types = { path = "../types", version = "0.15.1" }
thiserror = "1"
serde = { version = "1.0", default-features = false, features = ["derive"] }
serde_json = { version = "1", features = ["raw_value"] }
......@@ -51,6 +51,7 @@ server = [
"lazy_static",
"unicase",
"http",
"hyper",
]
client = ["futures-util/sink", "futures-channel/sink", "futures-channel/std"]
async-client = [
......
......@@ -247,19 +247,20 @@ impl ClientT for Client {
let _req_id = self.id_manager.next_request_id()?;
let notif = NotificationSer::new(method, params);
let trace = RpcTracing::batch();
let _enter = trace.span().enter();
async {
let raw = serde_json::to_string(&notif).map_err(Error::ParseError)?;
tx_log_from_str(&raw, self.max_log_length);
let mut sender = self.to_back.clone();
let fut = sender.send(FrontToBack::Notification(raw)).in_current_span();
let fut = sender.send(FrontToBack::Notification(raw));
match future::select(fut, Delay::new(self.request_timeout)).await {
Either::Left((Ok(()), _)) => Ok(()),
Either::Left((Err(_), _)) => Err(self.read_error_from_backend().await),
Either::Right((_, _)) => Err(Error::RequestTimeout),
}
}.instrument(trace.into_span()).await
}
async fn request<'a, R>(&self, method: &'a str, params: Option<ParamsSer<'a>>) -> Result<R, Error>
......@@ -270,8 +271,8 @@ impl ClientT for Client {
let guard = self.id_manager.next_request_id()?;
let id = guard.inner();
let trace = RpcTracing::method_call(method);
let _enter = trace.span().enter();
async {
let raw = serde_json::to_string(&RequestSer::new(&id, method, params)).map_err(Error::ParseError)?;
tx_log_from_str(&raw, self.max_log_length);
......@@ -285,7 +286,7 @@ impl ClientT for Client {
return Err(self.read_error_from_backend().await);
}
let res = call_with_timeout(self.request_timeout, send_back_rx).in_current_span().await;
let res = call_with_timeout(self.request_timeout, send_back_rx).await;
let json_value = match res {
Ok(Ok(v)) => v,
Ok(Err(err)) => return Err(err),
......@@ -295,18 +296,18 @@ impl ClientT for Client {
rx_log_from_json(&Response::new(&json_value, id), self.max_log_length);
serde_json::from_value(json_value).map_err(Error::ParseError)
}.instrument(trace.into_span()).await
}
async fn batch_request<'a, R>(&self, batch: Vec<(&'a str, Option<ParamsSer<'a>>)>) -> Result<Vec<R>, Error>
where
R: DeserializeOwned + Default + Clone,
{
let trace = RpcTracing::batch();
async {
let guard = self.id_manager.next_request_ids(batch.len())?;
let batch_ids: Vec<Id> = guard.inner();
let mut batches = Vec::with_capacity(batch.len());
let log = RpcTracing::batch();
let _enter = log.span().enter();
for (idx, (method, params)) in batch.into_iter().enumerate() {
batches.push(RequestSer::new(&batch_ids[idx], method, params));
}
......@@ -327,7 +328,7 @@ impl ClientT for Client {
return Err(self.read_error_from_backend().await);
}
let res = call_with_timeout(self.request_timeout, send_back_rx).in_current_span().await;
let res = call_with_timeout(self.request_timeout, send_back_rx).await;
let json_values = match res {
Ok(Ok(v)) => v,
Ok(Err(err)) => return Err(err),
......@@ -339,6 +340,7 @@ impl ClientT for Client {
let values: Result<_, _> =
json_values.into_iter().map(|val| serde_json::from_value(val).map_err(Error::ParseError)).collect();
Ok(values?)
}.instrument(trace.into_span()).await
}
}
......@@ -364,8 +366,8 @@ impl SubscriptionClientT for Client {
let guard = self.id_manager.next_request_ids(2)?;
let mut ids: Vec<Id> = guard.inner();
let trace = RpcTracing::method_call(subscribe_method);
let _enter = trace.span().enter();
async {
let id = ids[0].clone();
let raw = serde_json::to_string(&RequestSer::new(&id, subscribe_method, params)).map_err(Error::ParseError)?;
......@@ -389,7 +391,7 @@ impl SubscriptionClientT for Client {
return Err(self.read_error_from_backend().await);
}
let res = call_with_timeout(self.request_timeout, send_back_rx).in_current_span().await;
let res = call_with_timeout(self.request_timeout, send_back_rx).await;
let (notifs_rx, sub_id) = match res {
Ok(Ok(val)) => val,
......@@ -400,6 +402,7 @@ impl SubscriptionClientT for Client {
rx_log_from_json(&Response::new(&sub_id, id), self.max_log_length);
Ok(Subscription::new(self.to_back.clone(), notifs_rx, SubscriptionKind::Subscription(sub_id)))
}.instrument(trace.into_span()).await
}
/// Subscribe to a specific method.
......
......@@ -46,7 +46,7 @@ cfg_http_helpers! {
cfg_server! {
pub mod id_providers;
pub mod server;
pub mod middleware;
pub mod logger;
}
cfg_client! {
......
......@@ -24,28 +24,56 @@
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//! Middleware for `jsonrpsee` servers.
//! Logger for `jsonrpsee` servers.
use std::net::SocketAddr;
pub use http::request::Request;
pub use http::HeaderMap as Headers;
pub use hyper::Body;
pub use jsonrpsee_types::Params;
/// Defines a middleware specifically for HTTP requests with callbacks during the RPC request life-cycle.
/// The type JSON-RPC v2 call, it can be a subscription, method call or unknown.
#[derive(Debug, Copy, Clone)]
pub enum MethodKind {
/// Subscription Call.
Subscription,
/// Unsubscription Call.
Unsubscription,
/// Method call.
MethodCall,
/// Unknown method.
Unknown,
}
impl std::fmt::Display for MethodKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Self::Subscription => "subscription",
Self::MethodCall => "method call",
Self::Unknown => "unknown",
Self::Unsubscription => "unsubscription",
};
write!(f, "{}", s)
}
}
/// Defines a logger specifically for HTTP requests with callbacks during the RPC request life-cycle.
/// The primary use case for this is to collect timings for a larger metrics collection solution.
///
/// See [`HttpServerBuilder::set_middleware`](../../jsonrpsee_http_server/struct.HttpServerBuilder.html#method.set_middleware) method
/// See [`HttpServerBuilder::set_logger`](../../jsonrpsee_http_server/struct.HttpServerBuilder.html#method.set_logger) method
/// for examples.
pub trait HttpMiddleware: Send + Sync + Clone + 'static {
/// Intended to carry timestamp of a request, for example `std::time::Instant`. How the middleware
pub trait HttpLogger: Send + Sync + Clone + 'static {
/// Intended to carry timestamp of a request, for example `std::time::Instant`. How the trait
/// measures time, if at all, is entirely up to the implementation.
type Instant: std::fmt::Debug + Send + Sync + Copy;
/// Called when a new JSON-RPC request comes to the server.
fn on_request(&self, remote_addr: SocketAddr, headers: &Headers) -> Self::Instant;
fn on_request(&self, remote_addr: SocketAddr, request: &Request<Body>) -> Self::Instant;
/// Called on each JSON-RPC method call, batch requests will trigger `on_call` multiple times.
fn on_call(&self, method_name: &str, params: Params);
fn on_call(&self, method_name: &str, params: Params, kind: MethodKind);
/// Called on each JSON-RPC method completion, batch requests will trigger `on_result` multiple times.
fn on_result(&self, method_name: &str, success: bool, started_at: Self::Instant);
......@@ -54,13 +82,13 @@ pub trait HttpMiddleware: Send + Sync + Clone + 'static {
fn on_response(&self, result: &str, _started_at: Self::Instant);
}
/// Defines a middleware specifically for WebSocket connections with callbacks during the RPC request life-cycle.
/// Defines a logger specifically for WebSocket connections with callbacks during the RPC request life-cycle.
/// The primary use case for this is to collect timings for a larger metrics collection solution.
///
/// See the [`WsServerBuilder::set_middleware`](../../jsonrpsee_ws_server/struct.WsServerBuilder.html#method.set_middleware)
/// See the [`WsServerBuilder::set_logger`](../../jsonrpsee_ws_server/struct.WsServerBuilder.html#method.set_logger)
/// for examples.
pub trait WsMiddleware: Send + Sync + Clone + 'static {
/// Intended to carry timestamp of a request, for example `std::time::Instant`. How the middleware
pub trait WsLogger: Send + Sync + Clone + 'static {
/// Intended to carry timestamp of a request, for example `std::time::Instant`. How the trait
/// measures time, if at all, is entirely up to the implementation.
type Instant: std::fmt::Debug + Send + Sync + Copy;
......@@ -71,7 +99,7 @@ pub trait WsMiddleware: Send + Sync + Clone + 'static {
fn on_request(&self) -> Self::Instant;
/// Called on each JSON-RPC method call, batch requests will trigger `on_call` multiple times.
fn on_call(&self, method_name: &str, params: Params);
fn on_call(&self, method_name: &str, params: Params, kind: MethodKind);
/// Called on each JSON-RPC method completion, batch requests will trigger `on_result` multiple times.
fn on_result(&self, method_name: &str, success: bool, started_at: Self::Instant);
......@@ -83,26 +111,26 @@ pub trait WsMiddleware: Send + Sync + Clone + 'static {
fn on_disconnect(&self, remote_addr: std::net::SocketAddr);
}
impl HttpMiddleware for () {
impl HttpLogger for () {
type Instant = ();
fn on_request(&self, _: std::net::SocketAddr, _: &Headers) -> Self::Instant {}
fn on_request(&self, _: std::net::SocketAddr, _: &Request<Body>) -> Self::Instant {}
fn on_call(&self, _: &str, _: Params) {}
fn on_call(&self, _: &str, _: Params, _: MethodKind) {}
fn on_result(&self, _: &str, _: bool, _: Self::Instant) {}
fn on_response(&self, _: &str, _: Self::Instant) {}
}
impl WsMiddleware for () {
impl WsLogger for () {
type Instant = ();
fn on_connect(&self, _: std::net::SocketAddr, _: &Headers) {}
fn on_request(&self) -> Self::Instant {}
fn on_call(&self, _: &str, _: Params) {}
fn on_call(&self, _: &str, _: Params, _: MethodKind) {}
fn on_result(&self, _: &str, _: bool, _: Self::Instant) {}
......@@ -111,10 +139,10 @@ impl WsMiddleware for () {
fn on_disconnect(&self, _: std::net::SocketAddr) {}
}
impl<A, B> WsMiddleware for (A, B)
impl<A, B> WsLogger for (A, B)
where
A: WsMiddleware,
B: WsMiddleware,
A: WsLogger,
B: WsLogger,
{
type Instant = (A::Instant, B::Instant);
......@@ -126,9 +154,9 @@ where
(self.0.on_request(), self.1.on_request())
}
fn on_call(&self, method_name: &str, params: Params) {
self.0.on_call(method_name, params.clone());
self.1.on_call(method_name, params);
fn on_call(&self, method_name: &str, params: Params, kind: MethodKind) {
self.0.on_call(method_name, params.clone(), kind);
self.1.on_call(method_name, params, kind);
}
fn on_result(&self, method_name: &str, success: bool, started_at: Self::Instant) {
......@@ -146,20 +174,20 @@ where
}
}
impl<A, B> HttpMiddleware for (A, B)
impl<A, B> HttpLogger for (A, B)
where
A: HttpMiddleware,
B: HttpMiddleware,
A: HttpLogger,
B: HttpLogger,