https://github.com/pratik-codes/rust-forward-proxy
A high-performance HTTP/HTTPS forward proxy server written in Rust with full tunneling support and comprehensive logging.
https://github.com/pratik-codes/rust-forward-proxy
Last synced: 7 months ago
JSON representation
A high-performance HTTP/HTTPS forward proxy server written in Rust with full tunneling support and comprehensive logging.
- Host: GitHub
- URL: https://github.com/pratik-codes/rust-forward-proxy
- Owner: pratik-codes
- Created: 2025-09-01T17:00:29.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-24T20:10:34.000Z (9 months ago)
- Last Synced: 2025-09-24T21:31:21.684Z (9 months ago)
- Language: Rust
- Homepage:
- Size: 207 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ Rust Forward Proxy
[](https://www.rust-lang.org)
[](LICENSE)
[]()
A **high-performance HTTP/HTTPS forward proxy server** written in Rust with advanced TLS interception, certificate management, and comprehensive logging capabilities.
## โจ Features
### ๐ **Complete HTTPS Interception**
- **TLS Termination & Re-encryption** - Full decrypt/inspect/re-encrypt capability
- **Certificate Generation** - Automatic domain certificate creation with CA signing
- **Certificate Caching** - Memory & Redis backends for 25-30x performance improvement
- **Multiple Certificate Modes** - Support for rootCA and Securly CA certificates
### ๐ **Full Proxy Capabilities**
- **HTTP Request Interception** - Complete request/response logging and modification
- **HTTPS CONNECT Tunneling** - Standards-compliant tunnel for encrypted traffic
- **Dual Server Mode** - Simultaneous HTTP (8080) and HTTPS (8443) operation
- **Production Logging** - Clean INFO level for production, detailed DEBUG for development
### โก **High Performance**
- **Async Architecture** - Built on Tokio/Hyper for maximum throughput
- **Connection Pooling** - Efficient upstream connection management
- **Smart Body Handling** - Optimized request/response body processing
- **Certificate Caching** - Sub-millisecond certificate retrieval
### ๐ง **Developer Experience**
- **Comprehensive CLI Tools** - Certificate generation, validation, and server management
- **Flexible Configuration** - Environment variables + configuration files
- **Docker Support** - Production-ready containerization with Redis
- **Extensive Documentation** - Complete guides for setup, deployment, and usage
## ๐ Quick Start
### **Simple HTTP Proxy**
```bash
# Start basic HTTP proxy
make dev
# Test HTTP request
curl -x http://127.0.0.1:8080 http://httpbin.org/get
# Test HTTPS tunneling
curl -x http://127.0.0.1:8080 https://httpbin.org/get
```
### **HTTPS Interception (See Encrypted Content)**
```bash
# Setup root CA certificate for browser
make setup-ca
# Start HTTPS interception proxy
make dev
# Configure browser proxy: 127.0.0.1:8080
# Install rootCA.crt in browser (see BROWSER_SETUP.md)
# Browse to https://httpbin.org/get
# Check proxy logs - you'll see complete HTTPS content!
```
### **Production Deployment**
```bash
# Production with Docker + Redis caching
make prod-docker
# Local production mode
make prod
```
## ๐ Project Structure
```
rust-forward-proxy/
โโโ ๐ฆ src/ # Core implementation
โ โโโ ๐ proxy/ # HTTP/HTTPS proxy logic
โ โ โโโ server.rs # Main server implementation
โ โ โโโ http_client.rs # Optimized upstream client
โ โ โโโ streaming.rs # Smart body handling
โ โโโ ๐ tls/ # TLS & certificate management
โ โ โโโ server.rs # HTTPS termination server
โ โ โโโ cert_gen.rs # Certificate generation
โ โ โโโ cache.rs # Certificate caching (Memory/Redis)
โ โ โโโ config.rs # TLS configuration
โ โโโ โ๏ธ config/ # Configuration management
โ โโโ ๐ logging/ # Production-grade logging
โ โโโ ๐ ๏ธ utils/ # HTTP/URL/Time utilities
โ โโโ ๐ฎ cli/ # Command-line interface
โ โโโ ๐ models/ # Data structures
โโโ ๐ docs/ # Comprehensive documentation
โโโ ๐ณ docker-compose.yml # Docker deployment
โโโ ๐ Makefile # Development commands
โโโ ๐งช scripts/ # Testing & setup scripts
```
## ๐ฏ How It Works
### **HTTP Request Flow**
```
Client โ [HTTP Proxy:8080] โ [Full Interception] โ [Log Everything] โ Upstream
โ โ
โ [Response Logging] โ
โ โ
โโโโโโโโโโโโโโโโโโโโ Clean Response โโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
### **HTTPS Interception Flow**
```
Client โ [HTTPS Proxy:8443] โ [TLS Terminate] โ [Decrypt] โ [Log Content] โ [Re-encrypt] โ Upstream
โ โ
โ [Certificate Cache] โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโ Encrypted Response โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
### **Certificate Generation Flow**
```
Request for domain.com
โ
[Cache Check] โ Hit: Return cached cert (0ms)
โ
Miss: Generate new cert (5-10ms)
โ
[Sign with CA] โ Cache for 24h โ Return cert
```
## ๐ง Configuration
### **Certificate Modes**
```bash
# Default mode (uses rootCA)
make dev
# Securly CA mode
CERT=securly make dev
# or
make dev-securly
```
### **Environment Variables**
```bash
# Proxy Configuration
PROXY_LISTEN_ADDR=127.0.0.1:8080
HTTPS_LISTEN_ADDR=127.0.0.1:8443
# TLS Configuration
TLS_ENABLED=true
TLS_INTERCEPTION_ENABLED=true
TLS_CA_CERT_PATH=ca-certs/rootCA.crt
TLS_CA_KEY_PATH=ca-certs/rootCA.key
# Logging
RUST_LOG=info # Clean production logs
RUST_LOG=debug # Verbose development logs
# Redis (for certificate caching)
REDIS_URL=redis://redis:6379
```
## ๐ Documentation
### **๐ Getting Started**
- **[Quick Setup Guide](docs/SETUP.md)** - Get running in 5 minutes
- **[Browser Configuration](docs/BROWSER_SETUP.md)** - Setup HTTPS interception
- **[Certificate Management](docs/CERTIFICATES.md)** - Complete certificate guide
### **๐๏ธ Architecture & Implementation**
- **[Architecture Overview](docs/architecture.md)** - System design and flow diagrams
- **[TLS Implementation](docs/CERTIFICATES.md)** - HTTPS termination and certificate handling
- **[Performance Optimization](docs/performance.md)** - Caching, pooling, and benchmarks
### **๐ Deployment & Operations**
- **[Deployment Guide](docs/deployment.md)** - Docker, Kubernetes, cloud deployment
- **[Configuration Reference](docs/CONFIGURATION.md)** - Complete config documentation
- **[CLI Reference](docs/CONFIGURATION.md)** - CLI commands and configuration options
## ๐งช Testing
```bash
# Test basic functionality
make test
# Test HTTPS interception
make test-intercept
# Test Docker deployment
make test-docker
# Run all tests
make test-all
```
## ๐ฏ Use Cases
### **๐ Development & Debugging**
- **API Development** - See exactly what your applications send/receive
- **Security Testing** - Analyze encrypted traffic for vulnerabilities
- **Network Debugging** - Troubleshoot mysterious network issues
### **๐ก๏ธ Security & Monitoring**
- **Traffic Analysis** - Monitor and log all HTTP/HTTPS traffic
- **Content Filtering** - Inspect and potentially modify requests/responses
- **Compliance Auditing** - Log all network communications
### **โก Performance Testing**
- **Load Testing** - Proxy traffic for performance analysis
- **Caching Analysis** - Understand application caching behavior
- **Bandwidth Monitoring** - Track data usage and patterns
## ๐ Performance
### **Benchmarks**
- **HTTP Throughput**: 1000+ requests/second
- **HTTPS Latency**: +2-5ms overhead for interception
- **Certificate Generation**: 5-10ms first request, <1ms cached
- **Memory Usage**: ~10-50MB depending on load
- **Concurrent Connections**: 1000+ simultaneous HTTPS sessions
### **Certificate Caching Performance**
```
Without Caching: 25-30ms per HTTPS request
With Caching: <1ms per HTTPS request
Performance Gain: 25-30x improvement
```
## ๐ค Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## ๐ Acknowledgments
- Built with [Rust](https://www.rust-lang.org/) and [Tokio](https://tokio.rs/)
- Uses [Hyper](https://hyper.rs/) for HTTP implementation
- TLS powered by [rustls](https://github.com/rustls/rustls)
- Certificate generation via [rcgen](https://github.com/est31/rcgen)
---
## ๐ Ready to Start?
```bash
# Clone and run
git clone
cd rust-forward-proxy
make dev
# Start intercepting HTTP traffic in seconds!
curl -x http://127.0.0.1:8080 http://httpbin.org/get
```
**๐ฅ For HTTPS interception, see our [Browser Setup Guide](docs/BROWSER_SETUP.md) to configure certificate trust!**