mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-27 00:00:24 +02:00
"matchit" based router (#363)
* "matchit" based router * Update changelog * Remove dependency on `regex` * Docs * Fix typos * Also mention route order in root module docs * Update CHANGELOG.md Co-authored-by: Jonas Platte <[email protected]> * Document that `/:key` and `/foo` overlaps * Provide good error message for wildcards in routes * minor clean ups * Make `Router` cheaper to clone * Ensure middleware still only applies to routes above * Remove call to issues from changelog We're aware of the short coming :) * Fix tests on 1.51 Co-authored-by: Jonas Platte <[email protected]>
This commit is contained in:
co-authored by
Jonas Platte
parent
9fcc884374
commit
1a78a3f224
@@ -176,6 +176,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::tests::*;
|
||||
use crate::{handler::get, Router};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[tokio::test]
|
||||
async fn percent_decoding() {
|
||||
@@ -190,4 +191,27 @@ mod tests {
|
||||
|
||||
assert_eq!(res.text().await, "one two");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn wildcard() {
|
||||
let app = Router::new()
|
||||
.route(
|
||||
"/foo/*rest",
|
||||
get(|Path(param): Path<String>| async move { param }),
|
||||
)
|
||||
.route(
|
||||
"/bar/*rest",
|
||||
get(|Path(params): Path<HashMap<String, String>>| async move {
|
||||
params.get("rest").unwrap().clone()
|
||||
}),
|
||||
);
|
||||
|
||||
let client = TestClient::new(app);
|
||||
|
||||
let res = client.get("/foo/bar/baz").send().await;
|
||||
assert_eq!(res.text().await, "/bar/baz");
|
||||
|
||||
let res = client.get("/bar/baz/qux").send().await;
|
||||
assert_eq!(res.text().await, "/baz/qux");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user