3 releases (breaking)
| 0.4.0 | Nov 27, 2025 |
|---|---|
| 0.2.0 | Nov 23, 2025 |
| 0.1.0 | Nov 22, 2025 |
#262 in HTTP server
Used in avila
255KB
6K
SLoC
π avx-http - Pure Rust HTTP/1.1 + HTTP/2 Library
100% proprietary HTTP implementation with ZERO external dependencies!
π― 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
- PHASE_COMPLETE.md - Implementation details
- NEXT-LEVEL.md - Future roadmap
- examples/ - Code examples
- API Docs - Full API reference
π‘ 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:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Built with β€οΈ for the AVL Platform and Brazilian research infrastructure π§π·
Dependencies
~0β12MB
~88K SLoC