mini-static 0.38.5

A secure, async static file server with streaming, traversal protection, and connection limits.
Documentation
//! The plainest possible `mini-static` server, for `bench/throughput.sh`.
//!
//! No SPA mode, no live reload, no immutable-asset predicate — every one of those adds
//! per-request work, and a throughput baseline should measure the crate's floor rather
//! than one deployment's feature set. Single-threaded on purpose: the comparison against
//! nginx is one worker each, and a multi-threaded runtime would measure the machine.

use std::env;
use std::path::Path;
use std::time::Duration;

#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let port: u16 = env::var("PORT").unwrap_or_else(|_| "8081".into()).parse()?;
    let root = env::var("ROOT").unwrap_or_else(|_| "./bench/www".into());

    let mut server = mini_static::Server::new(Path::new(&root))?;
    if std::env::var("NO_PRECOMPRESSED").is_ok() {
        server = server.without_precompressed();
    }
    // SPA mode makes HTML responses injectable, which already short-circuits the sidecar
    // probe. Toggleable here so that claim can be measured rather than asserted.
    // `CACHE=<bytes>` serves from an eager content cache, for `bench/throughput.sh`.
    if let Ok(budget) = std::env::var("CACHE") {
        server = server
            .with_content_cache(budget.parse().unwrap_or(64 << 20))
            .expect("no live-reload configured in this example");
    }
    if std::env::var("SPA").is_ok() {
        server = server.with_spa_root("#root");
    }
    let (bound, handle) = server
        .run_on(([127, 0, 0, 1], port).into(), Duration::from_secs(30))
        .await?;
    eprintln!("bench server on {bound}");

    tokio::signal::ctrl_c().await?;
    handle.shutdown().await;
    Ok(())
}