"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:
David Pedersen
2021-10-24 15:22:49 +02:00
committed by GitHub
co-authored by Jonas Platte
parent 9fcc884374
commit 1a78a3f224
11 changed files with 553 additions and 413 deletions
+1 -9
View File
@@ -50,14 +50,11 @@ where
}
fn call(&mut self, req: Request<ReqBody>) -> Self::Future {
let original_uri = req.uri().clone();
ResponseFuture {
state: State::FirstFuture {
f: self.first.clone().oneshot(req),
},
second: Some(self.second.clone()),
original_uri: Some(original_uri),
}
}
}
@@ -72,9 +69,6 @@ pin_project! {
#[pin]
state: State<A, B, ReqBody>,
second: Option<B>,
// Some services, namely `Nested`, mutates the request URI so we must
// restore it to its original state before calling `second`
original_uri: Option<http::Uri>,
}
}
@@ -109,7 +103,7 @@ where
StateProj::FirstFuture { f } => {
let mut response = ready!(f.poll(cx)?);
let mut req = if let Some(ext) = response
let req = if let Some(ext) = response
.extensions_mut()
.remove::<FromEmptyRouter<ReqBody>>()
{
@@ -118,8 +112,6 @@ where
return Poll::Ready(Ok(response));
};
*req.uri_mut() = this.original_uri.take().unwrap();
let second = this.second.take().expect("future polled after completion");
State::SecondFuture {