2021-06-07 16:28:40 +02:00
|
|
|
//! Async functions that can be used to handle requests.
|
|
|
|
|
|
2021-06-06 11:37:08 +02:00
|
|
|
use crate::{
|
2021-07-22 13:23:50 +02:00
|
|
|
body::{box_body, BoxBody},
|
2021-09-19 17:51:25 +02:00
|
|
|
extract::{FromRequest, RequestParts},
|
2021-06-06 11:37:08 +02:00
|
|
|
response::IntoResponse,
|
2021-08-15 23:01:26 +02:00
|
|
|
routing::{EmptyRouter, MethodFilter},
|
2021-08-16 09:19:37 +02:00
|
|
|
util::Either,
|
2021-08-21 15:01:30 +02:00
|
|
|
BoxError,
|
2021-06-06 11:37:08 +02:00
|
|
|
};
|
2021-05-30 13:24:03 +02:00
|
|
|
use async_trait::async_trait;
|
2021-06-01 17:17:10 +02:00
|
|
|
use bytes::Bytes;
|
2021-05-30 13:24:03 +02:00
|
|
|
use http::{Request, Response};
|
|
|
|
|
use std::{
|
2021-05-31 22:54:21 +02:00
|
|
|
convert::Infallible,
|
2021-06-07 15:45:19 +02:00
|
|
|
fmt,
|
2021-05-30 13:24:03 +02:00
|
|
|
future::Future,
|
|
|
|
|
marker::PhantomData,
|
|
|
|
|
task::{Context, Poll},
|
|
|
|
|
};
|
2021-08-21 15:01:30 +02:00
|
|
|
use tower::ServiceExt;
|
|
|
|
|
use tower_layer::Layer;
|
|
|
|
|
use tower_service::Service;
|
2021-06-06 23:58:44 +02:00
|
|
|
|
2021-06-08 12:43:16 +02:00
|
|
|
pub mod future;
|
2021-08-19 21:16:44 +02:00
|
|
|
mod into_service;
|
|
|
|
|
|
|
|
|
|
pub use self::into_service::IntoService;
|
2021-06-08 12:43:16 +02:00
|
|
|
|
2021-09-19 10:28:15 +02:00
|
|
|
/// Route requests with any standard HTTP method to the given handler.
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
|
|
|
|
/// # Example
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
2021-08-18 00:04:15 +02:00
|
|
|
/// use axum::{
|
|
|
|
|
/// handler::any,
|
2021-08-19 22:37:48 +02:00
|
|
|
/// Router,
|
2021-08-18 00:04:15 +02:00
|
|
|
/// };
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
2021-06-09 09:03:09 +02:00
|
|
|
/// async fn handler() {}
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
2021-08-19 22:37:48 +02:00
|
|
|
/// let app = Router::new().route("/", any(handler));
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # async {
|
2021-08-04 15:38:51 +02:00
|
|
|
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # };
|
2021-06-07 15:45:19 +02:00
|
|
|
/// ```
|
2021-09-19 10:28:15 +02:00
|
|
|
///
|
|
|
|
|
/// Note that this only accepts the standard HTTP methods. If you need to
|
|
|
|
|
/// support non-standard methods use [`Handler::into_service`]:
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// use axum::{
|
|
|
|
|
/// handler::Handler,
|
|
|
|
|
/// Router,
|
|
|
|
|
/// };
|
|
|
|
|
///
|
|
|
|
|
/// async fn handler() {}
|
|
|
|
|
///
|
|
|
|
|
/// let app = Router::new().route("/", handler.into_service());
|
|
|
|
|
/// # async {
|
|
|
|
|
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
|
|
|
|
/// # };
|
|
|
|
|
/// ```
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn any<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
on(MethodFilter::all(), handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Route `CONNECT` requests to the given handler.
|
|
|
|
|
///
|
|
|
|
|
/// See [`get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn connect<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
on(MethodFilter::CONNECT, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Route `DELETE` requests to the given handler.
|
|
|
|
|
///
|
|
|
|
|
/// See [`get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn delete<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
on(MethodFilter::DELETE, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
2021-06-06 11:37:08 +02:00
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Route `GET` requests to the given handler.
|
|
|
|
|
///
|
|
|
|
|
/// # Example
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
2021-08-18 00:04:15 +02:00
|
|
|
/// use axum::{
|
|
|
|
|
/// handler::get,
|
2021-08-19 22:37:48 +02:00
|
|
|
/// Router,
|
2021-08-18 00:04:15 +02:00
|
|
|
/// };
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
2021-06-09 09:03:09 +02:00
|
|
|
/// async fn handler() {}
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
|
|
|
|
/// // Requests to `GET /` will go to `handler`.
|
2021-08-19 22:37:48 +02:00
|
|
|
/// let app = Router::new().route("/", get(handler));
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # async {
|
2021-08-04 15:38:51 +02:00
|
|
|
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # };
|
2021-06-07 15:45:19 +02:00
|
|
|
/// ```
|
2021-08-15 20:27:13 +02:00
|
|
|
///
|
|
|
|
|
/// Note that `get` routes will also be called for `HEAD` requests but will have
|
|
|
|
|
/// the response body removed. Make sure to add explicit `HEAD` routes
|
|
|
|
|
/// afterwards.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn get<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 11:37:08 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 11:37:08 +02:00
|
|
|
{
|
2021-08-15 20:27:13 +02:00
|
|
|
on(MethodFilter::GET | MethodFilter::HEAD, handler)
|
2021-06-06 11:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Route `HEAD` requests to the given handler.
|
|
|
|
|
///
|
|
|
|
|
/// See [`get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn head<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
on(MethodFilter::HEAD, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Route `OPTIONS` requests to the given handler.
|
|
|
|
|
///
|
|
|
|
|
/// See [`get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn options<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
on(MethodFilter::OPTIONS, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Route `PATCH` requests to the given handler.
|
|
|
|
|
///
|
|
|
|
|
/// See [`get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn patch<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
on(MethodFilter::PATCH, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Route `POST` requests to the given handler.
|
|
|
|
|
///
|
|
|
|
|
/// See [`get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn post<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 11:37:08 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 11:37:08 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
on(MethodFilter::POST, handler)
|
2021-06-06 11:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Route `PUT` requests to the given handler.
|
|
|
|
|
///
|
|
|
|
|
/// See [`get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn put<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
on(MethodFilter::PUT, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Route `TRACE` requests to the given handler.
|
|
|
|
|
///
|
|
|
|
|
/// See [`get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn trace<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
on(MethodFilter::TRACE, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Route requests with the given method to the handler.
|
|
|
|
|
///
|
|
|
|
|
/// # Example
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
2021-08-18 00:04:15 +02:00
|
|
|
/// use axum::{
|
|
|
|
|
/// handler::on,
|
2021-08-19 22:37:48 +02:00
|
|
|
/// Router,
|
2021-08-19 21:24:32 +02:00
|
|
|
/// routing::MethodFilter,
|
2021-08-18 00:04:15 +02:00
|
|
|
/// };
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
2021-06-09 09:03:09 +02:00
|
|
|
/// async fn handler() {}
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
|
|
|
|
/// // Requests to `POST /` will go to `handler`.
|
2021-08-19 22:37:48 +02:00
|
|
|
/// let app = Router::new().route("/", on(MethodFilter::POST, handler));
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # async {
|
2021-08-04 15:38:51 +02:00
|
|
|
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # };
|
2021-06-07 15:45:19 +02:00
|
|
|
/// ```
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn on<H, B, T>(method: MethodFilter, handler: H) -> OnMethod<H, B, T, EmptyRouter>
|
2021-06-06 11:37:08 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
2021-06-06 11:37:08 +02:00
|
|
|
{
|
2021-06-06 15:19:54 +02:00
|
|
|
OnMethod {
|
|
|
|
|
method,
|
2021-08-15 23:01:26 +02:00
|
|
|
handler,
|
2021-07-31 21:05:53 +02:00
|
|
|
fallback: EmptyRouter::method_not_allowed(),
|
2021-08-15 23:01:26 +02:00
|
|
|
_marker: PhantomData,
|
2021-06-06 15:19:54 +02:00
|
|
|
}
|
2021-06-06 11:37:08 +02:00
|
|
|
}
|
2021-05-30 13:24:03 +02:00
|
|
|
|
2021-07-30 15:19:53 +02:00
|
|
|
pub(crate) mod sealed {
|
2021-06-07 15:45:19 +02:00
|
|
|
#![allow(unreachable_pub, missing_docs, missing_debug_implementations)]
|
2021-06-06 11:37:08 +02:00
|
|
|
|
2021-05-30 13:24:03 +02:00
|
|
|
pub trait HiddentTrait {}
|
|
|
|
|
pub struct Hidden;
|
|
|
|
|
impl HiddentTrait for Hidden {}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Trait for async functions that can be used to handle requests.
|
|
|
|
|
///
|
|
|
|
|
/// You shouldn't need to depend on this trait directly. It is automatically
|
|
|
|
|
/// implemented to closures of the right types.
|
|
|
|
|
///
|
2021-06-08 12:43:16 +02:00
|
|
|
/// See the [module docs](crate::handler) for more details.
|
2021-05-30 13:24:03 +02:00
|
|
|
#[async_trait]
|
2021-08-20 23:56:16 +02:00
|
|
|
pub trait Handler<B, T>: Clone + Send + Sized + 'static {
|
2021-07-30 15:19:53 +02:00
|
|
|
// This seals the trait. We cannot use the regular "sealed super trait"
|
|
|
|
|
// approach due to coherence.
|
2021-05-30 13:24:03 +02:00
|
|
|
#[doc(hidden)]
|
|
|
|
|
type Sealed: sealed::HiddentTrait;
|
|
|
|
|
|
2021-08-20 23:56:16 +02:00
|
|
|
/// Call the handler with the given request.
|
|
|
|
|
async fn call(self, req: Request<B>) -> Response<BoxBody>;
|
2021-05-30 13:24:03 +02:00
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Apply a [`tower::Layer`] to the handler.
|
|
|
|
|
///
|
2021-06-08 12:43:16 +02:00
|
|
|
/// All requests to the handler will be processed by the layer's
|
|
|
|
|
/// corresponding middleware.
|
|
|
|
|
///
|
|
|
|
|
/// This can be used to add additional processing to a request for a single
|
|
|
|
|
/// handler.
|
|
|
|
|
///
|
2021-10-13 12:21:22 +02:00
|
|
|
/// Note this differs from [`routing::Router::layer`](crate::routing::Router::layer)
|
2021-06-08 12:43:16 +02:00
|
|
|
/// which adds a middleware to a group of routes.
|
|
|
|
|
///
|
2021-06-07 15:45:19 +02:00
|
|
|
/// # Example
|
|
|
|
|
///
|
|
|
|
|
/// Adding the [`tower::limit::ConcurrencyLimit`] middleware to a handler
|
2021-06-08 12:43:16 +02:00
|
|
|
/// can be done like so:
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
|
|
|
|
/// ```rust
|
2021-08-18 00:04:15 +02:00
|
|
|
/// use axum::{
|
|
|
|
|
/// handler::{get, Handler},
|
2021-08-19 22:37:48 +02:00
|
|
|
/// Router,
|
2021-08-18 00:04:15 +02:00
|
|
|
/// };
|
2021-06-07 15:45:19 +02:00
|
|
|
/// use tower::limit::{ConcurrencyLimitLayer, ConcurrencyLimit};
|
|
|
|
|
///
|
2021-06-09 09:03:09 +02:00
|
|
|
/// async fn handler() { /* ... */ }
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
|
|
|
|
/// let layered_handler = handler.layer(ConcurrencyLimitLayer::new(64));
|
2021-08-19 22:37:48 +02:00
|
|
|
/// let app = Router::new().route("/", get(layered_handler));
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # async {
|
2021-08-04 15:38:51 +02:00
|
|
|
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # };
|
2021-06-07 15:45:19 +02:00
|
|
|
/// ```
|
2021-08-15 23:01:26 +02:00
|
|
|
fn layer<L>(self, layer: L) -> Layered<L::Service, T>
|
2021-05-30 13:24:03 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
L: Layer<OnMethod<Self, B, T, EmptyRouter>>,
|
2021-05-30 13:24:03 +02:00
|
|
|
{
|
2021-08-15 23:01:26 +02:00
|
|
|
Layered::new(layer.layer(any(self)))
|
2021-05-30 13:24:03 +02:00
|
|
|
}
|
2021-08-19 21:16:44 +02:00
|
|
|
|
|
|
|
|
/// Convert the handler into a [`Service`].
|
|
|
|
|
///
|
|
|
|
|
/// This allows you to serve a single handler if you don't need any routing:
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
|
|
|
|
/// use axum::{
|
|
|
|
|
/// Server, handler::Handler, http::{Uri, Method}, response::IntoResponse,
|
|
|
|
|
/// };
|
|
|
|
|
/// use tower::make::Shared;
|
|
|
|
|
/// use std::net::SocketAddr;
|
|
|
|
|
///
|
|
|
|
|
/// async fn handler(method: Method, uri: Uri, body: String) -> impl IntoResponse {
|
|
|
|
|
/// format!("received `{} {}` with body `{:?}`", method, uri, body)
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// let service = handler.into_service();
|
|
|
|
|
///
|
|
|
|
|
/// # async {
|
|
|
|
|
/// Server::bind(&SocketAddr::from(([127, 0, 0, 1], 3000)))
|
|
|
|
|
/// .serve(Shared::new(service))
|
|
|
|
|
/// .await?;
|
|
|
|
|
/// # Ok::<_, hyper::Error>(())
|
|
|
|
|
/// # };
|
|
|
|
|
/// ```
|
2021-08-20 23:56:16 +02:00
|
|
|
fn into_service(self) -> IntoService<Self, B, T> {
|
2021-08-19 21:16:44 +02:00
|
|
|
IntoService::new(self)
|
|
|
|
|
}
|
2021-05-30 13:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[async_trait]
|
2021-08-20 23:56:16 +02:00
|
|
|
impl<F, Fut, Res, B> Handler<B, ()> for F
|
2021-05-30 13:24:03 +02:00
|
|
|
where
|
2021-08-15 23:01:26 +02:00
|
|
|
F: FnOnce() -> Fut + Clone + Send + Sync + 'static,
|
2021-05-31 20:42:57 +02:00
|
|
|
Fut: Future<Output = Res> + Send,
|
2021-06-06 22:41:52 +02:00
|
|
|
Res: IntoResponse,
|
2021-08-20 23:56:16 +02:00
|
|
|
B: Send + 'static,
|
2021-05-30 13:24:03 +02:00
|
|
|
{
|
|
|
|
|
type Sealed = sealed::Hidden;
|
|
|
|
|
|
2021-08-20 23:56:16 +02:00
|
|
|
async fn call(self, _req: Request<B>) -> Response<BoxBody> {
|
2021-07-22 13:23:50 +02:00
|
|
|
self().await.into_response().map(box_body)
|
2021-05-30 13:24:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
macro_rules! impl_handler {
|
2021-09-19 17:51:25 +02:00
|
|
|
( $($ty:ident),* $(,)? ) => {
|
2021-05-30 13:24:03 +02:00
|
|
|
#[async_trait]
|
|
|
|
|
#[allow(non_snake_case)]
|
2021-09-19 17:51:25 +02:00
|
|
|
impl<F, Fut, B, Res, $($ty,)*> Handler<B, ($($ty,)*)> for F
|
2021-05-30 13:24:03 +02:00
|
|
|
where
|
2021-09-19 17:51:25 +02:00
|
|
|
F: FnOnce($($ty,)*) -> Fut + Clone + Send + Sync + 'static,
|
2021-05-31 20:42:57 +02:00
|
|
|
Fut: Future<Output = Res> + Send,
|
2021-08-20 23:56:16 +02:00
|
|
|
B: Send + 'static,
|
2021-06-06 22:41:52 +02:00
|
|
|
Res: IntoResponse,
|
2021-09-19 17:51:25 +02:00
|
|
|
$( $ty: FromRequest<B> + Send,)*
|
2021-05-30 13:24:03 +02:00
|
|
|
{
|
|
|
|
|
type Sealed = sealed::Hidden;
|
|
|
|
|
|
2021-08-20 23:56:16 +02:00
|
|
|
async fn call(self, req: Request<B>) -> Response<BoxBody> {
|
2021-09-19 17:51:25 +02:00
|
|
|
let mut req = RequestParts::new(req);
|
2021-08-20 23:56:16 +02:00
|
|
|
|
|
|
|
|
$(
|
2021-09-19 17:51:25 +02:00
|
|
|
let $ty = match $ty::from_request(&mut req).await {
|
2021-08-20 23:56:16 +02:00
|
|
|
Ok(value) => value,
|
|
|
|
|
Err(rejection) => return rejection.into_response().map(box_body),
|
|
|
|
|
};
|
|
|
|
|
)*
|
|
|
|
|
|
2021-09-19 17:51:25 +02:00
|
|
|
let res = self($($ty,)*).await;
|
2021-08-20 23:56:16 +02:00
|
|
|
|
2021-09-19 17:51:25 +02:00
|
|
|
res.into_response().map(box_body)
|
2021-05-30 13:24:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-19 17:51:25 +02:00
|
|
|
impl_handler!(T1);
|
|
|
|
|
impl_handler!(T1, T2);
|
|
|
|
|
impl_handler!(T1, T2, T3);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6, T7);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6, T7, T8);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6, T7, T8, T9);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14);
|
|
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15);
|
2021-05-30 13:24:03 +02:00
|
|
|
impl_handler!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16);
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// A [`Service`] created from a [`Handler`] by applying a Tower middleware.
|
|
|
|
|
///
|
2021-06-08 12:43:16 +02:00
|
|
|
/// Created with [`Handler::layer`]. See that method for more details.
|
2021-05-30 13:24:03 +02:00
|
|
|
pub struct Layered<S, T> {
|
|
|
|
|
svc: S,
|
|
|
|
|
_input: PhantomData<fn() -> T>,
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
impl<S, T> fmt::Debug for Layered<S, T>
|
|
|
|
|
where
|
|
|
|
|
S: fmt::Debug,
|
|
|
|
|
{
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
|
f.debug_struct("Layered").field("svc", &self.svc).finish()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-30 13:24:03 +02:00
|
|
|
impl<S, T> Clone for Layered<S, T>
|
|
|
|
|
where
|
|
|
|
|
S: Clone,
|
|
|
|
|
{
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
Self::new(self.svc.clone())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[async_trait]
|
2021-08-20 23:56:16 +02:00
|
|
|
impl<S, T, ReqBody, ResBody> Handler<ReqBody, T> for Layered<S, T>
|
2021-05-30 13:24:03 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
S: Service<Request<ReqBody>, Response = Response<ResBody>> + Clone + Send + 'static,
|
2021-06-06 22:41:52 +02:00
|
|
|
S::Error: IntoResponse,
|
2021-05-30 13:24:03 +02:00
|
|
|
S::Future: Send,
|
2021-08-15 23:01:26 +02:00
|
|
|
T: 'static,
|
2021-06-19 12:50:33 +02:00
|
|
|
ReqBody: Send + 'static,
|
|
|
|
|
ResBody: http_body::Body<Data = Bytes> + Send + Sync + 'static,
|
|
|
|
|
ResBody::Error: Into<BoxError> + Send + Sync + 'static,
|
2021-05-30 13:24:03 +02:00
|
|
|
{
|
|
|
|
|
type Sealed = sealed::Hidden;
|
|
|
|
|
|
2021-08-20 23:56:16 +02:00
|
|
|
async fn call(self, req: Request<ReqBody>) -> Response<BoxBody> {
|
2021-05-31 22:54:21 +02:00
|
|
|
match self
|
|
|
|
|
.svc
|
2021-05-30 13:24:03 +02:00
|
|
|
.oneshot(req)
|
|
|
|
|
.await
|
2021-05-31 22:54:21 +02:00
|
|
|
.map_err(IntoResponse::into_response)
|
|
|
|
|
{
|
2021-07-22 13:23:50 +02:00
|
|
|
Ok(res) => res.map(box_body),
|
|
|
|
|
Err(res) => res.map(box_body),
|
2021-05-31 22:54:21 +02:00
|
|
|
}
|
2021-05-30 13:24:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<S, T> Layered<S, T> {
|
|
|
|
|
pub(crate) fn new(svc: S) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
svc,
|
|
|
|
|
_input: PhantomData,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-15 23:01:26 +02:00
|
|
|
/// A handler [`Service`] that accepts requests based on a [`MethodFilter`] and
|
|
|
|
|
/// allows chaining additional handlers.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub struct OnMethod<H, B, T, F> {
|
2021-08-15 23:01:26 +02:00
|
|
|
pub(crate) method: MethodFilter,
|
|
|
|
|
pub(crate) handler: H,
|
|
|
|
|
pub(crate) fallback: F,
|
2021-08-20 23:56:16 +02:00
|
|
|
pub(crate) _marker: PhantomData<fn() -> (B, T)>,
|
2021-05-30 13:24:03 +02:00
|
|
|
}
|
|
|
|
|
|
2021-08-26 20:59:55 +02:00
|
|
|
#[test]
|
|
|
|
|
fn traits() {
|
|
|
|
|
use crate::tests::*;
|
|
|
|
|
assert_send::<OnMethod<(), NotSendSync, NotSendSync, ()>>();
|
|
|
|
|
assert_sync::<OnMethod<(), NotSendSync, NotSendSync, ()>>();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-20 23:56:16 +02:00
|
|
|
impl<H, B, T, F> fmt::Debug for OnMethod<H, B, T, F>
|
2021-06-07 15:45:19 +02:00
|
|
|
where
|
2021-08-15 23:01:26 +02:00
|
|
|
T: fmt::Debug,
|
|
|
|
|
F: fmt::Debug,
|
2021-06-07 15:45:19 +02:00
|
|
|
{
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2021-08-15 23:01:26 +02:00
|
|
|
f.debug_struct("OnMethod")
|
|
|
|
|
.field("method", &self.method)
|
|
|
|
|
.field("handler", &format_args!("{}", std::any::type_name::<H>()))
|
|
|
|
|
.field("fallback", &self.fallback)
|
2021-06-07 15:45:19 +02:00
|
|
|
.finish()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-20 23:56:16 +02:00
|
|
|
impl<H, B, T, F> Clone for OnMethod<H, B, T, F>
|
2021-05-30 13:24:03 +02:00
|
|
|
where
|
|
|
|
|
H: Clone,
|
2021-08-15 23:01:26 +02:00
|
|
|
F: Clone,
|
2021-05-30 13:24:03 +02:00
|
|
|
{
|
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
|
Self {
|
2021-08-15 23:01:26 +02:00
|
|
|
method: self.method,
|
2021-05-30 13:24:03 +02:00
|
|
|
handler: self.handler.clone(),
|
2021-08-15 23:01:26 +02:00
|
|
|
fallback: self.fallback.clone(),
|
2021-06-06 11:37:08 +02:00
|
|
|
_marker: PhantomData,
|
2021-05-30 13:24:03 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-20 23:56:16 +02:00
|
|
|
impl<H, B, T, F> Copy for OnMethod<H, B, T, F>
|
2021-05-30 13:24:03 +02:00
|
|
|
where
|
2021-08-15 23:01:26 +02:00
|
|
|
H: Copy,
|
|
|
|
|
F: Copy,
|
2021-05-30 13:24:03 +02:00
|
|
|
{
|
|
|
|
|
}
|
2021-06-06 15:19:54 +02:00
|
|
|
|
2021-08-20 23:56:16 +02:00
|
|
|
impl<H, B, T, F> OnMethod<H, B, T, F> {
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will accept all requests regardless of
|
|
|
|
|
/// its HTTP method.
|
|
|
|
|
///
|
|
|
|
|
/// See [`OnMethod::get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn any<H2, T2>(self, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
self.on(MethodFilter::all(), handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will only accept `CONNECT` requests.
|
|
|
|
|
///
|
|
|
|
|
/// See [`OnMethod::get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn connect<H2, T2>(self, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
self.on(MethodFilter::CONNECT, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will only accept `DELETE` requests.
|
|
|
|
|
///
|
|
|
|
|
/// See [`OnMethod::get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn delete<H2, T2>(self, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
self.on(MethodFilter::DELETE, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will only accept `GET` requests.
|
|
|
|
|
///
|
|
|
|
|
/// # Example
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
2021-08-19 22:37:48 +02:00
|
|
|
/// use axum::{handler::post, Router};
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
2021-06-09 09:03:09 +02:00
|
|
|
/// async fn handler() {}
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
2021-06-09 09:03:09 +02:00
|
|
|
/// async fn other_handler() {}
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
|
|
|
|
/// // Requests to `GET /` will go to `handler` and `POST /` will go to
|
|
|
|
|
/// // `other_handler`.
|
2021-08-19 22:37:48 +02:00
|
|
|
/// let app = Router::new().route("/", post(handler).get(other_handler));
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # async {
|
2021-08-04 15:38:51 +02:00
|
|
|
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # };
|
2021-06-07 15:45:19 +02:00
|
|
|
/// ```
|
2021-08-15 20:27:13 +02:00
|
|
|
///
|
|
|
|
|
/// Note that `get` routes will also be called for `HEAD` requests but will have
|
|
|
|
|
/// the response body removed. Make sure to add explicit `HEAD` routes
|
|
|
|
|
/// afterwards.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn get<H2, T2>(self, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 15:19:54 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 15:19:54 +02:00
|
|
|
{
|
2021-08-15 20:27:13 +02:00
|
|
|
self.on(MethodFilter::GET | MethodFilter::HEAD, handler)
|
2021-06-06 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will only accept `HEAD` requests.
|
|
|
|
|
///
|
|
|
|
|
/// See [`OnMethod::get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn head<H2, T2>(self, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
self.on(MethodFilter::HEAD, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will only accept `OPTIONS` requests.
|
|
|
|
|
///
|
|
|
|
|
/// See [`OnMethod::get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn options<H2, T2>(self, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
self.on(MethodFilter::OPTIONS, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will only accept `PATCH` requests.
|
|
|
|
|
///
|
|
|
|
|
/// See [`OnMethod::get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn patch<H2, T2>(self, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
self.on(MethodFilter::PATCH, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will only accept `POST` requests.
|
|
|
|
|
///
|
|
|
|
|
/// See [`OnMethod::get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn post<H2, T2>(self, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 15:19:54 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 15:19:54 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
self.on(MethodFilter::POST, handler)
|
2021-06-06 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will only accept `PUT` requests.
|
|
|
|
|
///
|
|
|
|
|
/// See [`OnMethod::get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn put<H2, T2>(self, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
self.on(MethodFilter::PUT, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will only accept `TRACE` requests.
|
|
|
|
|
///
|
|
|
|
|
/// See [`OnMethod::get`] for an example.
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn trace<H2, T2>(self, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 23:58:44 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 23:58:44 +02:00
|
|
|
{
|
2021-08-07 23:05:53 +02:00
|
|
|
self.on(MethodFilter::TRACE, handler)
|
2021-06-06 23:58:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-07 15:45:19 +02:00
|
|
|
/// Chain an additional handler that will accept requests matching the given
|
|
|
|
|
/// `MethodFilter`.
|
|
|
|
|
///
|
|
|
|
|
/// # Example
|
|
|
|
|
///
|
|
|
|
|
/// ```rust
|
2021-08-18 00:04:15 +02:00
|
|
|
/// use axum::{
|
|
|
|
|
/// handler::get,
|
2021-08-19 22:37:48 +02:00
|
|
|
/// Router,
|
2021-08-19 21:24:32 +02:00
|
|
|
/// routing::MethodFilter
|
2021-08-18 00:04:15 +02:00
|
|
|
/// };
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
2021-06-09 09:03:09 +02:00
|
|
|
/// async fn handler() {}
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
2021-06-09 09:03:09 +02:00
|
|
|
/// async fn other_handler() {}
|
2021-06-07 15:45:19 +02:00
|
|
|
///
|
|
|
|
|
/// // Requests to `GET /` will go to `handler` and `DELETE /` will go to
|
|
|
|
|
/// // `other_handler`
|
2021-08-19 22:37:48 +02:00
|
|
|
/// let app = Router::new().route("/", get(handler).on(MethodFilter::DELETE, other_handler));
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # async {
|
2021-08-04 15:38:51 +02:00
|
|
|
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
2021-06-19 12:50:33 +02:00
|
|
|
/// # };
|
2021-06-07 15:45:19 +02:00
|
|
|
/// ```
|
2021-08-20 23:56:16 +02:00
|
|
|
pub fn on<H2, T2>(self, method: MethodFilter, handler: H2) -> OnMethod<H2, B, T2, Self>
|
2021-06-06 15:19:54 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H2: Handler<B, T2>,
|
2021-06-06 15:19:54 +02:00
|
|
|
{
|
|
|
|
|
OnMethod {
|
|
|
|
|
method,
|
2021-08-15 23:01:26 +02:00
|
|
|
handler,
|
2021-06-06 15:19:54 +02:00
|
|
|
fallback: self,
|
2021-08-15 23:01:26 +02:00
|
|
|
_marker: PhantomData,
|
2021-06-06 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-20 23:56:16 +02:00
|
|
|
impl<H, B, T, F> Service<Request<B>> for OnMethod<H, B, T, F>
|
2021-06-06 15:19:54 +02:00
|
|
|
where
|
2021-08-20 23:56:16 +02:00
|
|
|
H: Handler<B, T>,
|
|
|
|
|
F: Service<Request<B>, Response = Response<BoxBody>, Error = Infallible> + Clone,
|
2021-08-15 23:01:26 +02:00
|
|
|
B: Send + 'static,
|
2021-06-06 15:19:54 +02:00
|
|
|
{
|
2021-06-13 10:10:37 +02:00
|
|
|
type Response = Response<BoxBody>;
|
2021-06-06 15:19:54 +02:00
|
|
|
type Error = Infallible;
|
2021-08-15 23:01:26 +02:00
|
|
|
type Future = future::OnMethodFuture<F, B>;
|
2021-06-06 15:19:54 +02:00
|
|
|
|
|
|
|
|
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
|
|
|
|
Poll::Ready(Ok(()))
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 12:50:33 +02:00
|
|
|
fn call(&mut self, req: Request<B>) -> Self::Future {
|
2021-08-15 20:27:13 +02:00
|
|
|
let req_method = req.method().clone();
|
|
|
|
|
|
2021-08-15 23:01:26 +02:00
|
|
|
let fut = if self.method.matches(req.method()) {
|
2021-08-20 23:56:16 +02:00
|
|
|
let fut = Handler::call(self.handler.clone(), req);
|
2021-08-16 09:19:37 +02:00
|
|
|
Either::A { inner: fut }
|
2021-06-06 15:19:54 +02:00
|
|
|
} else {
|
2021-06-12 23:59:18 +02:00
|
|
|
let fut = self.fallback.clone().oneshot(req);
|
2021-08-16 09:19:37 +02:00
|
|
|
Either::B { inner: fut }
|
2021-08-07 22:27:27 +02:00
|
|
|
};
|
|
|
|
|
|
2021-08-15 20:27:13 +02:00
|
|
|
future::OnMethodFuture {
|
2021-08-15 23:01:26 +02:00
|
|
|
inner: fut,
|
2021-08-15 20:27:13 +02:00
|
|
|
req_method,
|
|
|
|
|
}
|
2021-06-06 15:19:54 +02:00
|
|
|
}
|
|
|
|
|
}
|