-
SummaryHello, I'm wondering if axum handles requests within tokio tasks or not? If yes, is it safe to rely on this property to have a task_local value set by a middleware? (and only accessible for the current request) If that's not the case, I know how to implement my own custom middleware future that sets and unsets a thread-local value respectively before and after polling. I simply prefer to use existing framework features, if any. I am 100% aware that using thread_local/task_local stuff is very unidiomatic and could a big code smell, but in my specific case, I'm pretty sure that my current situation is way worse in terms of simplicity and maintainability. axum version0.6.18 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yes, you can use a task local to pass information about the request to inner middlewares, handlers and If is however also possible for inner middleware to do parts of its work (including calling the inner service) on different tasks though, making task locals unavailable. This is rare and something I would expect the middleware's docs to point out, though. |
Beta Was this translation helpful? Give feedback.
Yes, you can use a task local to pass information about the request to inner middlewares, handlers and
IntoResponse
impls. Though for all but the last one, you can also use request extensions.If is however also possible for inner middleware to do parts of its work (including calling the inner service) on different tasks though, making task locals unavailable. This is rare and something I would expect the middleware's docs to point out, though.