tokio-rs/axum

Nested routes return incorrect `request.uri()`

Closed this issue · 1 comments

  • I have looked for existing issues (including closed) about this

Bug Report

Version

0.7

Platform

Darwin Bens-MacBook-Pro.local 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 arm64

Description

When constructing nested routes, the nested routes request.raw_http_path() is incorrect.

I tried the following code:

let example_router = Router::new()
    // ...
    .route_layer(axum::middleware::from_fn(example_middleware));

let app = Router::new().nest("/example", example_router);

// ...

fn example_middleware(request: Request, next: Next) -> Result<Response, Json<Value>> {
  request.uri().to_string()
  // Resolves to https://example.com/my/route
  // Should resolve to https://example.com/example/my/route
}

This is intended. See OriginalUri.