This repository has been archived on 2024-10-26. You can view files and clone it, but cannot push or open issues or pull requests.
staxman-old/src/http/accept.rs

27 lines
671 B
Rust

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