Comments (2)
I think most of what you want is possible but you need to read the body of request/response which may be a little overhead.
for ws, only connection upgrade request is visible there in my understanding.
Simply you use utilize jsonrpsee as tower service and then you could do manage that yourself:
let svc = tower::service_fn(move |req: hyper::Request<hyper::body::Incoming>| {
let is_websocket = jsonrpsee::server::ws::is_upgrade_request(&req);
let transport_label = if is_websocket { "ws" } else { "http" };
// extract stuff that you are interested here from the request here
async move {
if is_websocket {
let on_disconnect = svc.on_session_closed();
// Spawn a task to handle when the connection is closed.
tokio::spawn(async move {
let now = std::time::Instant::now();
on_disconnect.await;
tracing::debug!("protocol: ws, duration: {now}")
});
}
let rp = svc.call(req).await;
// extract stuff that you are interested here from the response here
tracing::debug!("protocol: {transport_label}, ...")
}
});
Cannot implement at rpc moddleware because cannot access http level information such as response http status.
You can write custom RPC middleware layer that extract that stuff from the http request itself to be accessible for the rpc middleware, have look at this example
I think these APIs should be sufficiently flexible for anyone to implement what you want
from jsonrpsee.
I think most of what you want is possible but you need to read the body of request/response which may be a little overhead.
Yes, in case we read the body from hyper::body::Incoming
at somewhere other than call_with_service
fn. If possible, this step should be done only once to avoid reading twice.
Simply you use utilize jsonrpsee as tower service and then you could do manage that yourself:
In above code snippet, we can see connection upgrade req and rp, but cannot see websocket messages inside an established connection. ws message is recovered here in ws background task for the first time. so rpc method calls sent as ws message from client side cannot be detected at tower service (is not hyper::Request<hyper::body::Incoming>
) I think. (please correct me if I'm wrong)
You can write custom RPC middleware layer that extract that stuff from the http request itself to be accessible for the rpc middleware, have look at this example
Thank you! but what about http response status code? status code will be decided after exiting from rpc middlewares.
from jsonrpsee.
Related Issues (20)
- Can't use `params` as parameter name when using `subscription` proc-macro attribute HOT 5
- Strange behaviour when sending a web socket request. HOT 6
- Pass something from http middleware to rpc middleware HOT 4
- Username and password in the url ignored HOT 1
- Use async backpressure instead of MaxSlotsExceeded error HOT 1
- support RequestID as `null` HOT 1
- server: wrapping `jsonrpsee:TowerService` is a new type pattern is not possible
- Inheriting HTTP Header Option to RPC middlewares HOT 2
- server: `http extensions` are cloned for every rpc call
- Helper function for hyper v1 graceful shutdown HOT 1
- `0.23.0` `tls` feature relies on `rustls-platform-verifier`, bringing other unwanted dependencies HOT 4
- Failed response decoding breaks RPC connection HOT 10
- bug(transport): it should not try to resolve sockaddrs when using `build_with_stream` HOT 2
- Websocket: How to map a new connection request followed by json rpc request HOT 7
- Is there a way to close the subscription from the server? HOT 4
- server: add synchronization of ping/pong mechanism
- Unparseable notification HOT 4
- Expose current connections count as request extension HOT 4
- How to enable "gzip,deflate" for Jsonrpsee client? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonrpsee.