mini-static 0.31.3

A secure, async static file server with streaming, traversal protection, and connection limits.
Documentation
use super::*;

use crate::handler::FILE_CHUNK_SIZE;
use http_body_util::BodyExt;

// Disproves the prior implementation, which read every chunk into a `Vec` and
// only wrapped the whole result in a single `Full` frame at the end — that
// implementation would fail this test with `frame_count == 1` and
// `max_frame_len == file size`, regardless of `FILE_CHUNK_SIZE`.
#[tokio::test]
async fn file_body_yields_multiple_bounded_chunks_not_one_buffered_frame() {
    let dir = tempfile::TempDir::new().unwrap();
    let path = dir.path().join("big.bin");
    let content = vec![7u8; FILE_CHUNK_SIZE * 3 + 12_345];
    fs::write(&path, &content).unwrap();

    let file = File::open(&path).await.unwrap();
    let mut body = FileBody::new(file);

    let mut frame_count = 0usize;
    let mut max_frame_len = 0usize;
    let mut reassembled = Vec::new();

    while let Some(frame) = body.frame().await {
        let frame = frame.unwrap();
        let data = frame.into_data().unwrap();
        frame_count += 1;
        max_frame_len = max_frame_len.max(data.len());
        reassembled.extend_from_slice(&data);
    }

    assert!(
        frame_count > 1,
        "expected the file to be delivered as multiple frames, got {frame_count}"
    );
    assert!(
        max_frame_len <= FILE_CHUNK_SIZE,
        "no single frame should exceed the chunk size ({FILE_CHUNK_SIZE}), got {max_frame_len}"
    );
    assert_eq!(
        reassembled, content,
        "reassembled chunks must match original file content exactly"
    );
}