mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-03 17:52:18 +01:00
update to matchit 0.5 (#843)
This commit is contained in:
parent
19eda2f566
commit
04dd7617a4
2 changed files with 16 additions and 20 deletions
|
@ -33,7 +33,7 @@ http = "0.2.5"
|
||||||
http-body = "0.4.4"
|
http-body = "0.4.4"
|
||||||
hyper = { version = "0.14.14", features = ["server", "tcp", "stream"] }
|
hyper = { version = "0.14.14", features = ["server", "tcp", "stream"] }
|
||||||
itoa = "1.0.1"
|
itoa = "1.0.1"
|
||||||
matchit = "0.4.6"
|
matchit = "0.5.0"
|
||||||
memchr = "2.4.1"
|
memchr = "2.4.1"
|
||||||
mime = "0.3.16"
|
mime = "0.3.16"
|
||||||
percent-encoding = "2.1"
|
percent-encoding = "2.1"
|
||||||
|
|
|
@ -10,6 +10,7 @@ use crate::{
|
||||||
BoxError,
|
BoxError,
|
||||||
};
|
};
|
||||||
use http::{Request, Uri};
|
use http::{Request, Uri};
|
||||||
|
use matchit::MatchError;
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow,
|
borrow::Cow,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
|
@ -502,22 +503,17 @@ where
|
||||||
|
|
||||||
match self.node.at(&path) {
|
match self.node.at(&path) {
|
||||||
Ok(match_) => self.call_route(match_, req),
|
Ok(match_) => self.call_route(match_, req),
|
||||||
Err(err) => {
|
Err(MatchError::MissingTrailingSlash) => RouteFuture::from_response(
|
||||||
if err.tsr() {
|
Redirect::permanent(with_path(req.uri(), &format!("{}/", path))).into_response(),
|
||||||
let redirect_to = if let Some(without_tsr) = path.strip_suffix('/') {
|
),
|
||||||
with_path(req.uri(), without_tsr)
|
Err(MatchError::ExtraTrailingSlash) => RouteFuture::from_response(
|
||||||
} else {
|
Redirect::permanent(with_path(req.uri(), path.strip_suffix('/').unwrap()))
|
||||||
with_path(req.uri(), &format!("{}/", path))
|
.into_response(),
|
||||||
};
|
),
|
||||||
let res = Redirect::permanent(redirect_to);
|
Err(MatchError::NotFound) => match &self.fallback {
|
||||||
RouteFuture::from_response(res.into_response())
|
Fallback::Default(inner) => inner.clone().call(req),
|
||||||
} else {
|
Fallback::Custom(inner) => inner.clone().call(req),
|
||||||
match &self.fallback {
|
},
|
||||||
Fallback::Default(inner) => inner.clone().call(req),
|
|
||||||
Fallback::Custom(inner) => inner.clone().call(req),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -551,10 +547,10 @@ fn with_path(uri: &Uri, new_path: &str) -> Uri {
|
||||||
Uri::from_parts(parts).unwrap()
|
Uri::from_parts(parts).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wrapper around `matchit::Node` that supports merging two `Node`s.
|
/// Wrapper around `matchit::Router` that supports merging two `Router`s.
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
struct Node {
|
struct Node {
|
||||||
inner: matchit::Node<RouteId>,
|
inner: matchit::Router<RouteId>,
|
||||||
route_id_to_path: HashMap<RouteId, Arc<str>>,
|
route_id_to_path: HashMap<RouteId, Arc<str>>,
|
||||||
path_to_route_id: HashMap<Arc<str>, RouteId>,
|
path_to_route_id: HashMap<Arc<str>, RouteId>,
|
||||||
}
|
}
|
||||||
|
@ -579,7 +575,7 @@ impl Node {
|
||||||
fn at<'n, 'p>(
|
fn at<'n, 'p>(
|
||||||
&'n self,
|
&'n self,
|
||||||
path: &'p str,
|
path: &'p str,
|
||||||
) -> Result<matchit::Match<'n, 'p, &'n RouteId>, matchit::MatchError> {
|
) -> Result<matchit::Match<'n, 'p, &'n RouteId>, MatchError> {
|
||||||
self.inner.at(path)
|
self.inner.at(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue