pub struct PageResponse { /* private fields */ }Expand description
A rendered page, ready to send.
As axum’s IntoResponse it always writes, together with the HTML:
Cache-Control: no-store, because the HTML embeds a nonce minted for this one response; a cached copy would hand that nonce to every later reader, and another user’s page with it;Content-Security-Policy, the strict policy for that nonce (crate::csp::build_csp_header) with only the handler’s typedcrate::PolicyExtensionsadded;- Trusted Types enforcement in the strict policy, in every build and without
a reporting endpoint. The named route relaxation moves only those two
directives to
Content-Security-Policy-Report-Only; - Optional reporting through
crate::PolicyExtensions::report_toorcrate::PolicyExtensions::report_uri. Strict pages also carry a diagnostic Report-Only policy in debug builds; a relaxed route always carries it; Cross-Origin-Opener-Policy: same-origin(orsame-origin-allow-popupswhen the extensions ask for it),X-Content-Type-Options,Referrer-PolicyandPermissions-Policy;Content-Type: text/html; charset=utf-8.
A handler cannot take the HTML out and send it some other way except
through PageResponse::into_parts_unchecked, the one named exit, which
a consumer’s CI can search for:
let html = page().html; // private: the HTML leaves only with its headerslet parts = page().into_parts_unchecked(); // the named, searchable exitVerified by: crates/forma-server/tests/internal_renderer/page_response.rs > “page_response_writes_no_store_the_policy_and_the_document_headers”
Implementations§
Source§impl PageResponse
impl PageResponse
Sourcepub fn frame(preview: &PreviewFrame) -> Result<PageResponse, FrameError>
pub fn frame(preview: &PreviewFrame) -> Result<PageResponse, FrameError>
The preview frame’s document, ready to send: an opaque origin, the
runtime inline and allowed by its hash, and the requests the
frame module docs list closed, with their residuals
(the docs also set out the host’s side). The only response whose
policy is rewritten, and only in its nine directives.
As every PageResponse, it writes Cache-Control: no-store, the
document headers, and in a development build Trusted Types in
Report-Only (no endpoint), with it; its HTML is reachable apart from
them only through into_parts_unchecked().
§Errors
FRAME-201 when no nonce can be drawn for style-src: there is no
frame without one; FRAME-202, ruled out by the checks at start.
Verified by: crates/forma-server/tests/internal_renderer/preview_frame.rs > “the_frame_document_inlines_the_runtime_by_its_hash_and_names_nothing_to_fetch”
Source§impl PageResponse
impl PageResponse
Sourcepub fn counts(&self) -> RenderCounts
pub fn counts(&self) -> RenderCounts
What the render did: nodes, bytes and list rows walked, and time spent.
Sourcepub fn into_parts_unchecked(self) -> PageParts
pub fn into_parts_unchecked(self) -> PageParts
The HTML, its nonce and every header, apart.
The one way to reach the HTML without sending it as this response. It
exists for the rare handler that must assemble its own response (a
streaming body, a framework other than axum); each call site belongs
on the application’s raw-entry allowlist (forma-raw-lint) with an
owner.