based/src/request/context.rs
JMARyA 00bb6f152d
All checks were successful
ci/woodpecker/push/test Pipeline was successful
update
2024-12-30 21:23:28 +01:00

24 lines
677 B
Rust

use rocket::{
Request,
request::{self, FromRequest},
};
/// Represents contextual information about an HTTP request.
#[derive(Default)]
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<Self, Self::Error> {
rocket::outcome::Outcome::Success(RequestContext {
is_htmx: req.headers().get("HX-Request").next().is_some(),
})
}
}