use axum::{ async_trait, extract::FromRequestParts, http::{ header::{HeaderValue, ACCEPT}, request::Parts, StatusCode, }, }; pub struct ExtractAccept(pub HeaderValue); #[async_trait] impl FromRequestParts for ExtractAccept where S: Send + Sync, { type Rejection = (StatusCode, &'static str); async fn from_request_parts(parts: &mut Parts, state: &S) -> Result { if let Some(user_agent) = parts.headers.get(ACCEPT) { Ok(ExtractAccept(user_agent.clone())) } else { Err((StatusCode::BAD_REQUEST, "`User-Agent` header is missing")) } } }