laravel-rust-devtools 0.2.1

Developer tools for Laravel for Rust applications: an app inspector and request debugger in a floating toolbar.
Documentation
//! `/_devtools`: the panel's page, which the launcher opens in a frame. It holds no data: the panel
//! reads the API once it runs.

use laravel::container::Inject;
use laravel::http::{Response, header};

use super::access::Access;
use super::assets::{PANEL_SCRIPT, PANEL_STYLES};

/// Only the panel's own files, only in a frame of the application's own pages. The page has no
/// inline script or style, so it needs no nonce, and what a trace holds can't run as code even
/// where the panel would show it as markup; Trusted Types refuse markup from text, too. In a file
/// of its own, which the frontend's tests serve as well.
const POLICY: &str = include_str!("panel.csp").trim_ascii();

/// The page, with `{styles}` and `{script}` where the files' versions go, and `{login}` where it
/// says whether there is a login page.
const PAGE: &str = include_str!("panel.html");

/// `GET /_devtools`: the panel's page. Once the browser is no longer let in, the panel can ask
/// nothing, so the page tells it beforehand whether a key could let it in again.
pub(crate) async fn show(access: Inject<Access>) -> Response {
    let page = PAGE
        .replace("{styles}", &PANEL_STYLES.version())
        .replace("{script}", &PANEL_SCRIPT.version())
        .replace("{login}", if access.key.is_some() { "true" } else { "false" });

    Response::new(page).with_headers([
        (header::CONTENT_TYPE, "text/html; charset=utf-8"),
        (header::CONTENT_SECURITY_POLICY, POLICY),
        (header::X_FRAME_OPTIONS, "SAMEORIGIN"),
        (header::X_CONTENT_TYPE_OPTIONS, "nosniff"),
        (header::REFERRER_POLICY, "no-referrer"),
        (header::CACHE_CONTROL, "private, no-cache"),
    ])
}