use axum::extract::FromRequestParts; use axum::http::request::Parts; use axum::http::StatusCode; #[derive(Debug, PartialEq, Eq, Clone)] pub struct ExtractAcceptHeader(pub Option); impl FromRequestParts for ExtractAcceptHeader where B: Send + Sync, { type Rejection = (StatusCode, &'static str); async fn from_request_parts(parts: &mut Parts, _state: &B) -> Result { 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)) } }