2023-11-05 19:08:20 +00:00
|
|
|
use std::convert::Infallible;
|
|
|
|
|
|
|
|
use axum::{async_trait, extract::FromRequestParts, http::request::Parts};
|
|
|
|
|
|
|
|
const HX_REQUEST: &str = "HX-Request";
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone)]
|
2023-11-05 19:32:59 +00:00
|
|
|
pub struct HxRequest(pub bool);
|
2023-11-05 19:08:20 +00:00
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
impl<S> FromRequestParts<S> for HxRequest
|
|
|
|
where
|
|
|
|
S: Send + Sync,
|
|
|
|
{
|
|
|
|
type Rejection = Infallible;
|
|
|
|
|
|
|
|
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Infallible> {
|
|
|
|
Ok(HxRequest(parts.headers.get(HX_REQUEST).is_some()))
|
|
|
|
}
|
|
|
|
}
|