avx-http

Crates.ioavx-http
lib.rsavx-http
version0.4.0
created_at2025-11-22 21:08:20.853608+00
updated_at2025-11-27 15:54:50.986709+00
descriptionPure Rust HTTP/1.1 + HTTP/2 implementation with ZERO dependencies - no tokio, no serde, no hyper, 100% proprietary
homepagehttps://avila.inc
repositoryhttps://github.com/avilaops/arxis
max_upload_size
id1945738
size464,687
Nícolas Ávila (avilaops)

documentation

https://docs.rs/avx-http

README

🌐 avx-http - Pure Rust HTTP/1.1 + HTTP/2 Library

100% proprietary HTTP implementation with ZERO external dependencies!

Crates.io Documentation License

🎯 Why avx-http?

  • 🚫 ZERO Dependencies - No tokio, no hyper, no serde. Everything from scratch!
  • ⚑ Async Runtime - Custom runtime with epoll/kqueue/IOCP reactor
  • πŸ”₯ HTTP/2 Native - Full HTTP/2 with HPACK compression and multiplexing
  • πŸ”’ 100% Auditable - Complete control over every line of code
  • πŸ‡§πŸ‡· Brazilian Optimized - <10ms latency from SΓ£o Paulo
  • 🦸 Pure Rust - Memory safe, no C dependencies

πŸš€ Features

βœ… Async Runtime (NEW in v0.4.0!)

  • Custom ThreadPool - No tokio dependency
  • I/O Reactor - epoll (Linux), kqueue (macOS), IOCP (Windows)
  • Timer Wheel - Kafka-style hierarchical timers (O(1) operations)
  • Non-blocking TCP - AsyncTcpStream and AsyncTcpListener
  • Future-based API - Standard async/await support

βœ… HTTP/1.1 (Stable)

  • Zero-copy parser with finite state machine
  • Manual header parsing (no regex!)
  • Keep-alive connection pooling
  • Chunked transfer encoding
  • All standard methods (GET, POST, PUT, DELETE, etc.)

βœ… HTTP/2 (v0.4.0+)

  • Frame parsing - DATA, HEADERS, SETTINGS, PING, GOAWAY, etc.
  • HPACK compression - 50-70% header size reduction
  • Stream multiplexing - Multiple requests on single TCP connection
  • Flow control - Per-stream and connection-level windows
  • Priority - Stream dependencies and weights
  • Server push - Resource preloading (coming soon)

βš™οΈ Pure Rust Implementations

  • Custom async runtime - ThreadPool + I/O reactor (no tokio!)
  • Timer wheel - Hierarchical timeout management
  • Zero-copy bytes - Arc-based buffer with cheap cloning
  • JSON parser - Recursive descent, no serde needed
  • Network I/O - Async TCP with reactor integration

πŸ“¦ Installation

[dependencies]
avx-http = "0.4"

No other dependencies needed! Not even tokio.

🎯 Quick Start

Async HTTP Server

use avx_http::async_net::AsyncTcpListener;
use avx_http::runtime;

async fn handle_client(mut stream: avx_http::async_net::AsyncTcpStream) {
    let mut buf = vec![0u8; 1024];
    let n = stream.read(&mut buf).await.unwrap();

    let response = b"HTTP/1.1 200 OK\r\nContent-Length: 13\r\n\r\nHello, World!";
    stream.write_all(response).await.unwrap();
}

#[avx_http::main]
async fn main() {
    let listener = AsyncTcpListener::bind("127.0.0.1:8080").unwrap();

    loop {
        let (stream, _) = listener.accept().await.unwrap();
        runtime::spawn(handle_client(stream));
    }
}

HTTP/1.1 Client

use avx_http::{Request, Response, Method};
use avx_http::net::TcpStream;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create request
    let mut req = Request::new(Method::Get, "/api/data");
    req.headers.insert("Host", "api.avila.cloud");
    req.headers.insert("User-Agent", "avx-http/0.4.0");

    // Send over TCP
    let mut stream = TcpStream::connect("api.avila.cloud:80")?;
    stream.write_all(&req.to_bytes())?;

    // Read response
    let mut buffer = vec![0u8; 4096];
    let n = stream.read(&mut buffer)?;
    let response = Response::parse(&buffer[..n])?;

    println!("Status: {}", response.status);
    println!("Body: {}", response.body_str()?);

    Ok(())
}

HTTP/2 Client

use avx_http::http2::Http2Connection;
use avx_http::net::TcpStream;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Connect
    let stream = TcpStream::connect("api.avila.cloud:443")?;
    let mut conn = Http2Connection::new_client(stream)?;

    // Send request
    let stream_id = conn.request(
        "GET",
        "/data",
        "api.avila.cloud",
        vec![
            ("user-agent".into(), "avx-http/0.4.0".into()),
            ("accept".into(), "application/json".into()),
        ],
        None, // No body
    )?;

    println!("Request sent on stream {}", stream_id);

    // Read response frames
    while let Some((sid, frame)) = conn.read_frame()? {
        if sid == stream_id {
            // Process frame (HEADERS, DATA, etc.)
            println!("Received frame for stream {}", sid);
        }
    }

    Ok(())
}

JSON Parsing (No serde!)

use avx_http::json::JsonValue;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let json = r#"{"name": "Alice", "age": 30, "active": true}"#;
    let value = JsonValue::parse(json)?;

    if let Some(obj) = value.as_object() {
        println!("Name: {}", obj.get("name").unwrap().as_str().unwrap());
        println!("Age: {}", obj.get("age").unwrap().as_f64().unwrap());
    }

    // Serialize back
    println!("JSON: {}", value.to_string());

    Ok(())
}

πŸ“Š Architecture

HTTP/2 Frame Flow

Client                           Server
  |                                |
  |-- CONNECTION_PREFACE --------->|
  |-- SETTINGS ------------------>|
  |<-- SETTINGS -------------------|
  |-- SETTINGS (ACK) ------------>|
  |                                |
  |-- HEADERS (stream 1) -------->|
  |-- DATA (stream 1) ----------->|
  |<-- HEADERS (stream 1) ---------|
  |<-- DATA (stream 1) ------------|
  |                                |
  |-- HEADERS (stream 3) -------->|  Multiplexing!
  |<-- HEADERS (stream 3) ---------|
  |<-- DATA (stream 3) ------------|

HPACK Compression Example

Before:  "content-type: application/json" (32 bytes)
After:   0x82                              (1 byte)
         ↑ index into static table
Compression ratio: 97%!

Zero-Copy Bytes

let original = Bytes::from(vec![1, 2, 3, 4, 5]);
let slice1 = original.slice(0..2); // [1, 2]
let slice2 = original.slice(2..5); // [3, 4, 5]

// All three share the same underlying Vec!
// No memcpy, just Arc::clone() and pointer arithmetic

πŸ§ͺ Testing

# Run all tests
cargo test -p avx-http

# Run HTTP/2 specific tests
cargo test -p avx-http http2

# Run benchmarks
cargo bench -p avx-http

# Test JSON parser
cargo test -p avx-http json

πŸ—ΊοΈ Roadmap

  • HTTP/1.1 parser (FSM-based)
  • HTTP/1.1 client/server
  • HTTP/2 frame parsing
  • HPACK compression/decompression
  • HTTP/2 stream multiplexing
  • Flow control (per-stream + connection)
  • Custom async runtime (ThreadPool)
  • Zero-copy bytes buffer
  • JSON parser (no serde)
  • HTTP/2 server push
  • TLS 1.3 (via rustls)
  • HTTP/3 / QUIC
  • WebSocket
  • Server-Sent Events (SSE)
  • Real async I/O (epoll/kqueue/IOCP)

πŸ“š Documentation

πŸ’‘ Design Decisions

Why no Tokio?

  • Full control - No hidden allocations or thread spawning
  • Predictable - Deterministic performance
  • Simple - Easy to debug and profile
  • Educational - Learn how async I/O really works

Why no serde?

  • Fast compilation - serde adds 10s+ to build time
  • Simple JSON - Most APIs use simple structures
  • Zero-copy - Can slice strings without allocation
  • Type-safe - Still get Rust's type safety

Why no hyper?

  • Learning - Understand HTTP/2 deeply
  • Control - Optimize for Brazilian networks
  • Auditability - See every line of protocol code
  • Fun - Building protocols is awesome! πŸš€

🀝 Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

πŸ“„ License

Licensed under either of:

at your option.


Built with ❀️ for the AVL Platform and Brazilian research infrastructure πŸ‡§πŸ‡·

Commit count: 0

cargo fmt