OriginalUri is an extractor that provides the original request URI, even when the service is nested or the URI has been modified by middleware.
Basic usage
Difference from Uri
When using nested services, the regularUri extractor has the nesting prefix stripped, while OriginalUri preserves it:
Using in middleware
OriginalUri can be accessed from middleware via request extensions:
When to use OriginalUri
Use
OriginalUri when you need the full path as it was originally requested, especially in nested services or when middleware modifies the URI.Use cases
- Logging the full request path: Track complete URLs in nested services
- Redirects: Generate redirect URLs based on the original request
- Authentication: Check the full path against access control lists
- Middleware that modifies URIs: Access the pre-modification URI
Type signature
OriginalUri is a tuple struct containing a Uri:
Uri
The original HTTP URI from the request.
Deref behavior
OriginalUri implements Deref<Target = Uri>, so you can call Uri methods directly:
Rejection
OriginalUri is infallible - it will always succeed. If no OriginalUri extension exists, it falls back to the current request URI.
The
OriginalUri extension is automatically added by Axum’s router for all requests. It will only be missing if another extractor or middleware has removed it.Example: Full path logging in nested routers
See also
- Uri - Extract the current request URI (may be modified by nesting)
- MatchedPath - Extract the route pattern that matched