mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 19:22:26 +00:00
82 lines
2.0 KiB
Rust
82 lines
2.0 KiB
Rust
use axum::{extract::Request, response::Response};
|
|
use futures_util::future::BoxFuture;
|
|
use headers::Allow;
|
|
use http::Method;
|
|
use std::{convert::Infallible, str::FromStr};
|
|
|
|
pub type MethodFunction<State> =
|
|
fn(State, Request) -> BoxFuture<'static, Result<Response, Infallible>>;
|
|
|
|
pub trait AxumMethods: Sized + Send + Sync + 'static {
|
|
#[inline]
|
|
fn report() -> Option<MethodFunction<Self>> {
|
|
None
|
|
}
|
|
|
|
#[inline]
|
|
fn get() -> 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 put() -> Option<MethodFunction<Self>> {
|
|
None
|
|
}
|
|
|
|
#[inline]
|
|
fn import() -> Option<MethodFunction<Self>> {
|
|
None
|
|
}
|
|
|
|
#[inline]
|
|
fn allow_header() -> Allow {
|
|
let mut allow = vec![
|
|
Method::from_str("PROPFIND").unwrap(),
|
|
Method::from_str("PROPPATCH").unwrap(),
|
|
Method::from_str("COPY").unwrap(),
|
|
Method::from_str("MOVE").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);
|
|
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::put().is_some() {
|
|
allow.push(Method::PUT);
|
|
}
|
|
if Self::import().is_some() {
|
|
allow.push(Method::from_str("IMPORT").unwrap());
|
|
}
|
|
|
|
allow.into_iter().collect()
|
|
}
|
|
}
|