mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-16 14:33:02 +01:00
More clearly document what wildcards matches (#1873)
This commit is contained in:
parent
2600c22703
commit
a0af61ea46
2 changed files with 33 additions and 0 deletions
|
@ -50,6 +50,11 @@ Examples:
|
|||
- `/assets/*path`
|
||||
- `/:id/:repo/*tree`
|
||||
|
||||
Note that `/*key` doesn't match empty segments. Thus:
|
||||
|
||||
- `/*key` doesn't match `/` but does match `/a`, `/a/`, etc.
|
||||
- `/x/*key` doesn't match `/x` or `/x/` but does match `/x/a`, `/x/a/`, etc.
|
||||
|
||||
Wildcard captures can also be extracted using [`Path`](crate::extract::Path).
|
||||
Note that the leading slash is not included, i.e. for the route `/foo/*rest` and
|
||||
the path `/foo/bar/baz` the value of `rest` will be `bar/baz`.
|
||||
|
|
|
@ -380,6 +380,34 @@ async fn wildcard_doesnt_match_just_trailing_slash() {
|
|||
assert_eq!(res.text().await, "foo/bar");
|
||||
}
|
||||
|
||||
#[crate::test]
|
||||
async fn what_matches_wildcard() {
|
||||
let app = Router::new()
|
||||
.route("/*key", get(|| async { "root" }))
|
||||
.route("/x/*key", get(|| async { "x" }))
|
||||
.fallback(|| async { "fallback" });
|
||||
|
||||
let client = TestClient::new(app);
|
||||
|
||||
let get = |path| {
|
||||
let f = client.get(path).send();
|
||||
async move { f.await.text().await }
|
||||
};
|
||||
|
||||
assert_eq!(get("/").await, "fallback");
|
||||
assert_eq!(get("/a").await, "root");
|
||||
assert_eq!(get("/a/").await, "root");
|
||||
assert_eq!(get("/a/b").await, "root");
|
||||
assert_eq!(get("/a/b/").await, "root");
|
||||
|
||||
assert_eq!(get("/x").await, "root");
|
||||
assert_eq!(get("/x/").await, "root");
|
||||
assert_eq!(get("/x/a").await, "x");
|
||||
assert_eq!(get("/x/a/").await, "x");
|
||||
assert_eq!(get("/x/a/b").await, "x");
|
||||
assert_eq!(get("/x/a/b/").await, "x");
|
||||
}
|
||||
|
||||
#[crate::test]
|
||||
async fn static_and_dynamic_paths() {
|
||||
let app = Router::new()
|
||||
|
|
Loading…
Reference in a new issue