create extractor for hx-request
This commit is contained in:
parent
ba509400cb
commit
a4d6d79c16
2 changed files with 21 additions and 0 deletions
20
src/lib/hx_request.rs
Normal file
20
src/lib/hx_request.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
use std::convert::Infallible;
|
||||||
|
|
||||||
|
use axum::{async_trait, extract::FromRequestParts, http::request::Parts};
|
||||||
|
|
||||||
|
const HX_REQUEST: &str = "HX-Request";
|
||||||
|
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub struct HxRequest(bool);
|
||||||
|
|
||||||
|
#[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()))
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
pub mod models;
|
pub mod models;
|
||||||
pub mod schema;
|
pub mod schema;
|
||||||
pub mod report;
|
pub mod report;
|
||||||
|
pub mod hx_request;
|
||||||
|
|
Loading…
Reference in a new issue