You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A POST /widget/action request is properly routed to the widget_action handler, but match_pattern() function the HttpRequest incorrectly returns the /widgets/{id} pattern, since route guards are not considered (including the method guards).
Expected Behavior
I'd expect the match_pattern() function to return the actual pattern that was matched, not a synthetic routing evaluation that uses a subset of the full logic.
Current Behavior
match_pattern() may return incorrect results
Possible Solution
Perhaps the request could have internal state that indicates the actual routing evaluation, rather than re-evaluating without Guards when calling match_pattern().
Steps to Reproduce (for bugs)
The following code creates a minimal test server:
// cargo add [email protected][email protected]use actix_web::{dev::Serviceas _, web,App,HttpRequest,HttpResponse,HttpServer};use futures_util::future::FutureExt;#[actix_web::get("/widgets/{id}")]asyncfnget_widget(req:HttpRequest,id: web::Path<String>) -> HttpResponse{println!("[GET /widgets/{id}] Path: {}, Match Pattern: {:?}",
req.path(),
req.match_pattern());HttpResponse::Ok().body(format!("The widget ID is: {}\n", id))}#[actix_web::post("/widgets/action")]asyncfnwidget_action(req:HttpRequest) -> HttpResponse{println!("[POST /widgets/action] Path: {}, Match Pattern: {:?}",
req.path(),
req.match_pattern());HttpResponse::Ok().body("Performing the widget action\n")}#[actix_web::main]asyncfnmain() -> std::io::Result<()>{HttpServer::new(|| {App::new().wrap_fn(|req, srv| {println!("[Middleware] Path: {}, Match Pattern: {:?}",
req.path(),
req.match_pattern());
srv.call(req).map(|res| res)}).service(get_widget).service(widget_action)}).bind(("127.0.0.1",9999))?
.run().await}
We run this with cargo run and then test with:
$ curl -X POST http://localhost:9999/widgets/action
Performing the widget action
The server logs the following:
[Middleware] Path: /widgets/action, Match Pattern: Some("/widgets/{id}")
[POST /widgets/action] Path: /widgets/action, Match Pattern: Some("/widgets/{id}")
If the implementations matched the true routing logic, I would expect it to log the following:
[Middleware] Path: /widgets/action, Match Pattern: Some("/widgets/action")
[POST /widgets/action] Path: /widgets/action, Match Pattern: Some("/widgets/action")
Context
Your Environment
Rust Version (I.e, output of rustc -V): rustc 1.74.0 (79e9716c9 2023-11-13)
Actix Web Version: 4.5.1
The text was updated successfully, but these errors were encountered:
Suppose we have two routes that may match the same path:
and they are registered in an order such that the first pattern shadows the second if we ignore route guards:
A
POST /widget/action
request is properly routed to thewidget_action
handler, butmatch_pattern()
function theHttpRequest
incorrectly returns the/widgets/{id}
pattern, since route guards are not considered (including the method guards).Expected Behavior
I'd expect the
match_pattern()
function to return the actual pattern that was matched, not a synthetic routing evaluation that uses a subset of the full logic.Current Behavior
match_pattern()
may return incorrect resultsPossible Solution
Perhaps the request could have internal state that indicates the actual routing evaluation, rather than re-evaluating without Guards when calling
match_pattern()
.Steps to Reproduce (for bugs)
The following code creates a minimal test server:
We run this with
cargo run
and then test with:The server logs the following:
If the implementations matched the true routing logic, I would expect it to log the following:
Context
Your Environment
rustc -V
):rustc 1.74.0 (79e9716c9 2023-11-13)
4.5.1
The text was updated successfully, but these errors were encountered: