feat(axum): add safe html page composition
Add a SafeHtml PageRequest path for shell/partial composition and migrate examples so rendered hemplate fragments stay typed through the transport boundary instead of round-tripping through unchecked strings. req: axum_integration/001 req: html_safety/001 req: html_safety/002
This commit is contained in:
+12
-1
@@ -5,7 +5,7 @@ use axum::http::{header, request::Parts, HeaderMap, HeaderValue, Request, Respon
|
||||
use axum::response::sse::{Event, Sse};
|
||||
use axum::response::IntoResponse;
|
||||
use futures_util::{Stream, StreamExt};
|
||||
use slhx_core::{BuildFingerprint, EffectBatch, Handle, IntoEffect};
|
||||
use slhx_core::{BuildFingerprint, EffectBatch, Handle, IntoEffect, SafeHtml};
|
||||
use std::collections::BTreeMap;
|
||||
use std::convert::Infallible;
|
||||
|
||||
@@ -61,6 +61,17 @@ impl PageRequest {
|
||||
PageMode::Partial => PageResponse::partial(partial_html),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn page_html(
|
||||
self,
|
||||
partial_html: SafeHtml,
|
||||
shell: impl FnOnce(SafeHtml) -> SafeHtml,
|
||||
) -> PageResponse {
|
||||
match self.mode {
|
||||
PageMode::Full => PageResponse::full(shell(partial_html).into_string()),
|
||||
PageMode::Partial => PageResponse::partial(partial_html.into_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
||||
Reference in New Issue
Block a user