mini-static 0.14.7

A secure, async static file server with streaming, traversal protection, and connection limits.
Documentation
// Each integration-test binary compiles this module separately and uses only the
// helpers it needs, so anything the *current* binary doesn't call reads as dead.
#![allow(dead_code)]

use bytes::Bytes;
use http_body_util::BodyExt;
use hyper::{HeaderMap, Method, Response};
use mini_static::{ResponseBody, Server};

pub async fn body_bytes(response: Response<ResponseBody>) -> Bytes {
    response
        .into_body()
        .collect()
        .await
        .expect("body collection is infallible")
        .to_bytes()
}

/// Issue a request through the server's real request path, with no request headers.
///
/// A helper rather than a direct call so these tests exercise exactly what the accept
/// loop and `mini-unified` call — there is only one request path in the crate, and this
/// is it.
pub async fn request(server: &Server, method: &Method, path: &str) -> Response<ResponseBody> {
    server.handle_request(method, path, &HeaderMap::new()).await
}

/// Issue a `GET` through the server's real request path, with no request headers.
pub async fn get(server: &Server, path: &str) -> Response<ResponseBody> {
    request(server, &Method::GET, path).await
}

/// Issue a request carrying `headers`, given as `(name, value)` pairs.
pub async fn request_with_headers(
    server: &Server,
    method: &Method,
    path: &str,
    headers: &[(&str, &str)],
) -> Response<ResponseBody> {
    let mut map = HeaderMap::new();
    for (name, value) in headers {
        map.insert(
            hyper::header::HeaderName::from_bytes(name.as_bytes()).expect("valid header name"),
            value.parse().expect("valid header value"),
        );
    }
    server.handle_request(method, path, &map).await
}