Files
tuliprox/backend/src/api/endpoints/extract_accept_header.rs
T
2025-09-29 15:39:27 +02:00

24 lines
695 B
Rust

use axum::extract::FromRequestParts;
use axum::http::request::Parts;
use axum::http::StatusCode;
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct ExtractAcceptHeader(pub Option<String>);
impl<B> FromRequestParts<B> for ExtractAcceptHeader
where
B: Send + Sync,
{
type Rejection = (StatusCode, &'static str);
async fn from_request_parts(parts: &mut Parts, _state: &B) -> Result<Self, Self::Rejection> {
if let Some(accept_type) = parts.headers.get(axum::http::header::ACCEPT) {
if let Ok(val) = accept_type.to_str() {
return Ok(ExtractAcceptHeader(Some(val.to_string())));
}
}
Ok(ExtractAcceptHeader(None))
}
}