Skip to content

Seeking guidance on middleware stack usage before routing in Axum #3202

Answered by mladedav
NuclEnergy asked this question in Q&A
Discussion options

You must be logged in to vote
  1. No, this is correct and supported way to run middlewares pre-routing. However, I don't think I've seen other usage than NormalizePathLayer yet. You said you're doing this so that the layersrun even if they do not match a path. So the simplest thing you could do is to put all but the NormalizePathLayer as layers inside the Router. Of course you might not want to do that for some reasons, e.g. to have tracing called before the path normalization.
  2. Yes, just doing Router::new().route(...).layer(CompressionLayer::new()) should work. Feel free to ask another question if it doesn't for you.
  3. Yes, but I don't think they would be too bad. I think that the request mapping should do nothing (there's…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by NuclEnergy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants