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

@@ -1,7 +1,8 @@
#[cfg(feature = "actix")]
use actix_web::{HttpRequest, ResponseError};
#[cfg(feature = "axum")]
use axum::{body::Body, extract::FromRequestParts, response::IntoResponse};
use futures_util::future::{Ready, err, ok};
use http::StatusCode;
use rustical_xml::{ValueDeserialize, ValueSerialize, XmlError};
use thiserror::Error;
@@ -12,7 +13,17 @@ pub struct InvalidDepthHeader;
#[cfg(feature = "actix")]
impl ResponseError for InvalidDepthHeader {
fn status_code(&self) -> actix_web::http::StatusCode {
StatusCode::BAD_REQUEST
http_02::StatusCode::BAD_REQUEST
}
}
#[cfg(feature = "axum")]
impl IntoResponse for InvalidDepthHeader {
fn into_response(self) -> axum::response::Response {
axum::response::Response::builder()
.status(axum::http::StatusCode::BAD_REQUEST)
.body(Body::empty())
.expect("this always works")
}
}
@@ -81,3 +92,19 @@ impl actix_web::FromRequest for Depth {
Self::extract(req)
}
}
#[cfg(feature = "axum")]
impl<S: Send + Sync> FromRequestParts<S> for Depth {
type Rejection = InvalidDepthHeader;
async fn from_request_parts(
parts: &mut axum::http::request::Parts,
state: &S,
) -> Result<Self, Self::Rejection> {
if let Some(depth_header) = parts.headers.get("Depth") {
depth_header.as_bytes().try_into()
} else {
Ok(Self::Zero)
}
}
}