mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 18:12:27 +00:00
@@ -1,4 +1,8 @@
|
||||
use axum::{body::Body, extract::FromRequestParts, response::IntoResponse};
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::{FromRequestParts, OptionalFromRequestParts},
|
||||
response::IntoResponse,
|
||||
};
|
||||
use rustical_xml::{ValueDeserialize, ValueSerialize, XmlError};
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -59,6 +63,21 @@ impl TryFrom<&[u8]> for Depth {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Send + Sync> OptionalFromRequestParts<S> for Depth {
|
||||
type Rejection = InvalidDepthHeader;
|
||||
|
||||
async fn from_request_parts(
|
||||
parts: &mut axum::http::request::Parts,
|
||||
_state: &S,
|
||||
) -> Result<Option<Self>, Self::Rejection> {
|
||||
if let Some(depth_header) = parts.headers.get("Depth") {
|
||||
Ok(Some(depth_header.as_bytes().try_into()?))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S: Send + Sync> FromRequestParts<S> for Depth {
|
||||
type Rejection = InvalidDepthHeader;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user