Work on axum support

This commit is contained in:
Lennart
2025-06-07 20:17:50 +02:00
parent 57832116aa
commit 790c657b08
38 changed files with 582 additions and 64 deletions

View File

@@ -0,0 +1,94 @@
use axum::body::Body;
use futures_util::future::BoxFuture;
use headers::Allow;
use http::{Method, Request, Response};
use std::{convert::Infallible, str::FromStr, sync::Arc};
pub type MethodFunction<Service> =
fn(Arc<Service>, Request<Body>) -> BoxFuture<'static, Result<Response<Body>, Infallible>>;
pub trait AxumMethods: Sized + Send + Sync + 'static {
#[inline]
fn report() -> Option<MethodFunction<Self>> {
None
}
#[inline]
fn get() -> Option<MethodFunction<Self>> {
None
}
#[inline]
fn head() -> Option<MethodFunction<Self>> {
None
}
#[inline]
fn post() -> Option<MethodFunction<Self>> {
None
}
#[inline]
fn mkcol() -> Option<MethodFunction<Self>> {
None
}
#[inline]
fn mkcalendar() -> Option<MethodFunction<Self>> {
None
}
#[inline]
fn copy() -> Option<MethodFunction<Self>> {
None
}
#[inline]
fn mv() -> Option<MethodFunction<Self>> {
None
}
#[inline]
fn put() -> Option<MethodFunction<Self>> {
None
}
#[inline]
fn allow_header() -> Allow {
let mut allow = vec![
Method::from_str("PROPFIND").unwrap(),
Method::from_str("PROPPATCH").unwrap(),
Method::DELETE,
Method::OPTIONS,
];
if Self::report().is_some() {
allow.push(Method::from_str("REPORT").unwrap());
}
if Self::get().is_some() {
allow.push(Method::GET);
}
if Self::head().is_some() {
allow.push(Method::HEAD);
}
if Self::post().is_some() {
allow.push(Method::POST);
}
if Self::mkcol().is_some() {
allow.push(Method::from_str("MKCOL").unwrap());
}
if Self::mkcalendar().is_some() {
allow.push(Method::from_str("MKCALENDAR").unwrap());
}
if Self::copy().is_some() {
allow.push(Method::from_str("COPY").unwrap());
}
if Self::mv().is_some() {
allow.push(Method::from_str("MOVE").unwrap());
}
if Self::put().is_some() {
allow.push(Method::PUT);
}
allow.into_iter().collect()
}
}