A Zig implementation of the tinyproxy HTTP/HTTPS proxy daemon.
Built on top of the zio coroutine and async I/O framework.
- Single-threaded coroutine model: one coroutine per connection
- Async I/O: zio provides io_uring (Linux), kqueue (macOS), epoll fallback
- Feature parity goal: implement all tinyproxy features in idiomatic Zig
- Configuration file parsing (tinyproxy-compatible directives)
- Logging system (file/stderr/syslog + rotation on SIGUSR1)
- Forward proxy (HTTP)
- HTTPS CONNECT tunnel
- HTTP header processing (Via, hop-by-hop removal, response headers)
- Anonymous mode (header whitelist)
- Custom headers (AddHeader)
- ACL (Allow/Deny by IP/subnet)
- Basic Auth (with BasicAuthRealm)
- Connect port restriction
- URL/domain filtering (fnmatch, bre/ere patterns)
- Upstream proxy (HTTP + SOCKS4/SOCKS5 + NoUpstream)
- Reverse proxy (ReversePath, ReverseOnly, ReverseMagic, ReverseBaseURL)
- Transparent proxy (Linux SO_ORIGINAL_DST)
- Statistics page (StatHost, StatFile)
- Signal handling (SIGTERM/SIGINT/SIGUSR1/SIGHUP)
- Config reload on SIGHUP
- Daemon mode (daemonize, PID file, privilege drop)
- Custom error pages (ErrorFile, DefaultErrorFile)
zig buildzig build runProxy will listen on 127.0.0.1:9999 (see src/config.zig).
# Run unit tests
zig build test
# Test HTTP proxy
curl -x http://127.0.0.1:9999 http://ipinfo.io/ip
# Test HTTPS tunnel
curl -x http://127.0.0.1:9999 https://ipinfo.io/ip
# Benchmark
wrk -c 100 -t 4 http://127.0.0.1:9999See docs/roadmap.md for detailed implementation plan.
src/
├── main.zig # Entry point
├── runtime.zig # zio runtime wrapper
├── child.zig # Connection accept loop
├── request.zig # Request handling
├── relay.zig # Bidirectional data relay
├── buffer.zig # Line reader
├── config.zig # Configuration (WIP)
└── ...
Use mitmproxy for HTTP layer inspection or wireshark for TCP layer.
MIT License - Copyright Dacheng Gao