use rocket::{ Request, request::{self, FromRequest}, }; /// Represents contextual information about an HTTP request. pub struct RequestContext { /// A flag indicating if the request is an HTMX request. /// /// This is determined by checking the presence of the `HX-Request` header. pub is_htmx: bool, } #[rocket::async_trait] impl<'r> FromRequest<'r> for RequestContext { type Error = (); async fn from_request(req: &'r Request<'_>) -> request::Outcome { rocket::outcome::Outcome::Success(RequestContext { is_htmx: !req .headers() .get("HX-Request") .collect::>() .is_empty(), }) } }