mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-26 00:00:23 +02:00
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:
+1
-19
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user