#http #experience #tubes #test #axum-range

tubetti

Serve &[u8] data at a localhost url with minimal configuration

11 releases

Uses new Rust 2024

new 0.2.1 Apr 10, 2025
0.2.0 Apr 10, 2025
0.1.1 Apr 10, 2025
0.0.7 Mar 19, 2025
0.0.5 Feb 23, 2025

#226 in Testing

Download history 174/week @ 2025-02-10 462/week @ 2025-02-17 486/week @ 2025-02-24 570/week @ 2025-03-03 368/week @ 2025-03-10 721/week @ 2025-03-17 329/week @ 2025-03-24 395/week @ 2025-03-31 1079/week @ 2025-04-07

2,540 downloads per month

MIT/Apache

17KB
259 lines

Tubetti: small http tubes

No-fuss, low configuration webservers on demand

Features:

  • Convenience-focused development experience
  • Axum-based, can optionally be constructed from a Router
  • Supports ranged requests using axum-range
  • Supports custom headers using HeaderMap

Example Usage

    /// Prove macros work
    async fn test_tube_macros() {
        // most convenient, just give it some bytes and they're served on a random port
        let tb = tube!("potatoes".as_bytes()).await.unwrap();
        let client = Client::new();
        let response = client.get(tb.url()).send().await.unwrap();
        assert_eq!(response.bytes().await.unwrap(), "potatoes".as_bytes());
        tb.shutdown().await.unwrap();

        // with port
        let tb = tube!("potatoes".as_bytes(), Some(6301)).await.unwrap();
        assert_eq!(tb.url(), "http://0.0.0.0:6301".to_string());
        tb.shutdown().await.unwrap();

        // with port and status
        let tb = tube!(
            "potatoes".as_bytes(),
            Some(6301),
            Some(StatusCode::BAD_GATEWAY)
        )
        .await
        .unwrap();
        assert_eq!(tb.url(), "http://0.0.0.0:6301".to_string());
        let client = Client::new();
        let response = client.get(tb.url()).send().await.unwrap();
        assert_eq!(response.status(), 502);
        assert_eq!(response.bytes().await.unwrap(), "potatoes".as_bytes());
        tb.shutdown().await.unwrap();

        // with port, status and headers
        let mut headers = crate::axum::http::HeaderMap::new();
        headers.append("pasta", crate::axum::http::HeaderValue::from_static("yum"));
        let tb = tube!(
            "potatoes".as_bytes(),
            Some(6301),
            Some(StatusCode::BAD_GATEWAY),
            Some(headers)
        )
        .await
        .unwrap();
        assert_eq!(tb.url(), "http://0.0.0.0:6301".to_string());
        let client = Client::new();
        let response = client.get(tb.url()).send().await.unwrap();
        assert_eq!(response.status(), 502);
        assert_eq!(response.headers().get("pasta").unwrap(), "yum");
        assert_eq!(response.bytes().await.unwrap(), "potatoes".as_bytes());
        tb.shutdown().await.unwrap();

Caveats:

  • Under active development, expect breaking changes per-release until stable

License

MIT OR Apache-2.0

Dependencies

~8–14MB
~168K SLoC