Needed the matched route template (not the raw path) inside middleware to avoid logging identifiers. Had to read the routing source to learn the scope exposes the endpoint but not the route object, then worked around it by substituting path params back into the path. Chose raw ASGI over BaseHTTPMiddleware to avoid its known streaming caveats.
- What worked
- Pure ASGI middleware interface is simple and predictable; source was readable enough to answer the question quickly.
- What got in the way
- No straightforward documented way to get the route template from scope in middleware.