Fallback to calling next route if no methods match (#224)

This removes a small foot gun from the routing.

This means matching different HTTP methods for the same route that
aren't defined together now works.

So `Router::new().route("/", get(...)).route("/", post(...))` now
accepts both `GET` and `POST`. Previously only `POST` would be accepted.
This commit is contained in:
David Pedersen
2021-08-21 01:00:12 +02:00
committed by GitHub
parent 971c0a394a
commit 0d8f8b7b6c
6 changed files with 112 additions and 94 deletions
+1 -19
View File
@@ -1,6 +1,6 @@
//! [`Or`] used to combine two services into one.
use super::{FromEmptyRouter, OrDepth};
use super::FromEmptyRouter;
use crate::body::BoxBody;
use futures_util::ready;
use http::{Request, Response};
@@ -45,12 +45,6 @@ where
fn call(&mut self, mut req: Request<ReqBody>) -> Self::Future {
let original_uri = req.uri().clone();
if let Some(count) = req.extensions_mut().get_mut::<OrDepth>() {
count.increment();
} else {
req.extensions_mut().insert(OrDepth::new());
}
ResponseFuture {
state: State::FirstFuture {
f: self.first.clone().oneshot(req),
@@ -119,18 +113,6 @@ where
*req.uri_mut() = this.original_uri.take().unwrap();
let mut leaving_outermost_or = false;
if let Some(depth) = req.extensions_mut().get_mut::<OrDepth>() {
if depth == 1 {
leaving_outermost_or = true;
} else {
depth.decrement();
}
}
if leaving_outermost_or {
req.extensions_mut().remove::<OrDepth>();
}
let second = this.second.take().expect("future polled after completion");
State::SecondFuture {