-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RPC context extractor #450
Comments
Alright, I'm not super familiar how the However, sounds reasonable to me and if you want to work on it that would be really great. |
At the moment I'm extracting the origin of a request with this (simplified) extractor: #[derive(Debug, Clone)]
pub struct AppMetadata {
pub origin: Option<HeaderValue>,
}
#[derive(Debug, Default)]
pub struct AppMetaExtractor;
impl Metadata for AppMetadata {}
impl MetaExtractor<AppMetadata> for AppMetaExtractor {
fn read_metadata(&self, req: &Request<Body>) -> AppMetadata {
let origin = req.headers().get("origin").cloned();
AppMetadata { origin }
}
} And then hook it into the server when creating the server: let server = ServerBuilder::with_meta_extractor(io, AppMetaExtractor::default())
.threads(3)
.start_http(&"127.0.0.1:1248".parse().unwrap())?; My plan is to change the type of pub fn new_with_context_extractor(extractor: Fn<Request> -> Context) -> RpcModule<Context, Request> The main issue is that the same |
//cc @maciejhirsz could maybe be solved by |
@fracek We just merged #576 which adds limited support for middleware but your use case is not covered I'd say. I am skeptical about adding a second parameter to //cc @maciejhirsz Thoughts? |
Thanks for pinging me. I understand my issue is very niche, so I think the API doesn't have to be super-simple (like in the previous crate), it just needs to let me do it. I agree adding an extra type parameter is too invasive. |
We will extend the middleware to support this, see #699 TLDR; you will get:
Middleware is trait you can implement yourself to do custom things, However, duplicate of #699 so closing this |
I'm working on a project that needs to extract parts of the RPC context from the request. This is similar to what I can do in
jsonrpc
where I can register aMetaExtractor
to extract the handler metadata.If you're open to this but is not a priority, I can work on a PR for it.
The text was updated successfully, but these errors were encountered: