Replies: 1 comment 7 replies
-
If you want a dummy payload, you can use One solution is to simplify you responder type to do the async processing inside the handler. This is the easiest solution. If you REALLY need async Responder, you can achieve this with a middleware that posprocesses the response. You can pass arbitrary data from the responder impl to middleware using impl Responder for MyResponsder {
fn respond_to(self) {
HttpResponse::new().extensions_mut().insert(self)
}
}
App::new()
.wrap_fn(|req, srv| {
let fut = srv.call(req);
async move {
let resp = fut.await?;
let my_responder = req.extensions().remove::<MyResponder>();
if let Some(my) = my_responder {
// modify the response in async environ with payload
} else {
Ok(resp)
}
}
} |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I've got a custom type that I've written and implemented
FromRequest
, which means that I can receive an instance of it as a parameter to my handlers just fine.Is there any mechanism to do this when not in a handler though? Specifically, I'm wanting to do this in a
Responder
implementation and can't see any way to do this - both because thefrom_request()
method is async and because it needs both theHttpRequest
andPayload
.(For additional detail, my custom
FromRequest
type is the authorization details of the user, and myResponder
that wants to use it is because it will render differently depending on if and how the client is authorized.)In case it matters, this is using:
Cheers
Beta Was this translation helpful? Give feedback.
All reactions