mirror of
https://github.com/robertwayne/axum-htmx
synced 2024-12-01 23:44:32 +01:00
Add remaining request header extractors
This commit is contained in:
parent
119b01c592
commit
5fcf0c1e94
1 changed files with 42 additions and 0 deletions
|
@ -93,6 +93,48 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct HxHistoryRestoreRequest(pub bool);
|
||||||
|
|
||||||
|
#[axum::async_trait]
|
||||||
|
impl<S> FromRequestParts<S> for HxHistoryRestoreRequest
|
||||||
|
where
|
||||||
|
S: Send + Sync,
|
||||||
|
{
|
||||||
|
type Rejection = std::convert::Infallible;
|
||||||
|
|
||||||
|
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
||||||
|
if parts
|
||||||
|
.headers
|
||||||
|
.contains_key(HtmxRequestHeader::HistoryRestoreRequest.as_str())
|
||||||
|
{
|
||||||
|
return Ok(HxHistoryRestoreRequest(true));
|
||||||
|
} else {
|
||||||
|
return Ok(HxHistoryRestoreRequest(false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct HxPrompt(pub Option<String>);
|
||||||
|
|
||||||
|
#[axum::async_trait]
|
||||||
|
impl<S> FromRequestParts<S> for HxPrompt
|
||||||
|
where
|
||||||
|
S: Send + Sync,
|
||||||
|
{
|
||||||
|
type Rejection = std::convert::Infallible;
|
||||||
|
|
||||||
|
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
|
||||||
|
if let Some(prompt) = parts.headers.get(HtmxRequestHeader::Prompt.as_str()) {
|
||||||
|
if let Ok(prompt) = prompt.to_str() {
|
||||||
|
return Ok(HxPrompt(Some(prompt.to_string())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(HxPrompt(None));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct HxRequest(pub bool);
|
pub struct HxRequest(pub bool);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue