Skip to content

UVHTTPMemory-Safety-Verified C HTTP Server

A lightweight, embeddable C99 HTTP/1.1 & WebSocket library — the only one in its class verified clean under ASan and UBSan. Runs 32-bit embedded, serves 83K RPS on CI, leaks nothing. Throughput you can measure, memory safety you can prove.

📊 Performance Benchmarks ​

Key Metrics (v2.7.1, GitHub CI baseline) ​

Performance baselines are measured on GitHub Actions ubuntu-latest runners for hardware consistency. Previous local baselines (v2.6.x, ~20K RPS) were measured on developer hardware with 40%+ variance from CPU thermal throttling. The CI runner eliminates this variance (CV 0.4–2.4%), providing an authoritative, reproducible baseline.

MetricValueNotes
Peak Throughput~83K RPS10 conn, HTTP/1.1, GitHub CI runner
High Concurrency~55K RPS1000 concurrent connections
Static Files5.7K RPS~100KB body, benchmark_unified
API Routing82K RPSJSON endpoint
Average Latency~117µsP50, 10 connections
Error Rate0%Zero socket errors under load (10 conn)
Test Suite101/101 passASan + UBSan verified clean

Memory-Safety & Quality Highlights ​

  • AddressSanitizer: Full 101-test suite passes with leak detection enabled — zero leaks, zero use-after-free, zero buffer overflows
  • UndefinedBehaviorSanitizer: Full suite passes — zero undefined behavior
  • Test Cases: 101 unit/integration tests, all passing
  • CI/CD: Nightly ASan + UBSan jobs (see .github/workflows/ci-nightly.yml)
  • One-command verify: make verify-memory-safety — see Memory Safety
  • High-Coverage Modules (≥95%):
    • uvhttp_utils.c: 100.0%
    • uvhttp_error.c: 98.8%
    • uvhttp_version.c: 98.3%
    • uvhttp_error_helpers.c: 95.9%

Why UVHTTP (vs. other lightweight C HTTP libraries) ​

Most lightweight C HTTP libraries optimize for peak RPS and stop there. UVHTTP optimizes for the property that breaks production: memory safety. A per-connection leak or use-after-free that survives a 10-second benchmark will OOM an embedded device over a week. UVHTTP is the lightweight, embeddable, 32-bit-capable C library that proves — under both AddressSanitizer and UndefinedBehaviorSanitizer, on every nightly CI run — that those bugs are gone. |---------|:----------------😐:------😐:---------------------😐:-----------------------😐 | UVHTTP | ✅ | ✅ | ✅ 101/101, nightly CI | ✅ 101/101, nightly CI | | libuv-http | ✅ | ⚠️ | ❓ not advertised | ❓ not advertised | | microhttpd | ✅ | ⚠️ | ❓ not advertised | ❓ not advertised | | mongoose | ✅ | ✅ | ❓ not advertised | ❓ not advertised | | nginx | ❌ (standalone) | ✅ | ✅ (large team) | ❓ |

"not advertised" means the project publishes no sanitizer-clean test gate, so the absence of a finding is not verifiable. UVHTTP's is reproducible with make verify-memory-safety.

Performance Optimizations ​

  • Keep-Alive: connection reuse avoids re-establishing TCP per request
  • TCP: TCP_NODELAY and TCP_KEEPALIVE enabled by default
  • Router: O(1) prefix matching for route resolution
  • Allocation: optional mimalloc
  • libuv: called directly, no abstraction layer

🎯 Core Principles ​

1. Focus on Core Functionality ​

UVHTTP handles HTTP/1.1 and WebSocket protocol details; it does not impose business logic. The application keeps control over authentication, databases, and other features.

2. Zero Overhead Abstractions ​

Abstractions are compile-time macros with no runtime cost in production builds. The library calls libuv directly, with no intermediate layers.

3. Minimalist Engineering ​

The codebase favors simplicity. Self-contained dependencies and a clean architecture keep maintenance cost low.

4. Test Separation ​

Production code contains no test-specific code. Tests use linker wrapping and external mock frameworks, so the library ships clean.

5. Zero Global Variables ​

All state is held in libuv data pointers (loop->data or server->context). This enables multi-instance support and unit testing without global-state pollution.

6. Error Handling ​

A unified error type carries codes, descriptions, and recovery hints. Every failure point is checked and reported.


🌍 Platform Support ​

Current Status ​

  • ✅ Linux: Fully supported (primary platform)
  • 🔨 macOS: Work in progress
  • 🔨 Windows: Planned
  • 🔨 FreeBSD: Planned
  • 🔨 WebAssembly: Planned

Architecture Support ​

  • ✅ x86_64 (64-bit): Fully supported
  • ✅ x86 (32-bit): Fully supported with embedded optimizations
  • 🔨 ARM64: Planned for future releases

UVHTTP targets Linux, with 32-bit embedded support. Cross-platform expansion is on the roadmap.


🔧 Quick Installation ​

bash
# Clone repository with submodules
git clone --recurse-submodules https://github.com/adam-ikari/uvhttp.git
cd uvhttp

# Build with default options
make build

# Run example server
./build/dist/bin/hello_world

For detailed installation instructions and build options, see the Installation Guide.


📚 Documentation ​

Released under MIT License