🎥 Video-Recording link - https://drive.google.com/file/d/1PwWpocsb_ngd_QkXpCTevizuKfKWGwhD/view?usp=sharing
This project implements a fully functional HTTP/HTTPS proxy server in C++ from scratch. The proxy supports standard HTTP requests (via curl -x) and HTTPS traffic using the CONNECT method with secure bidirectional tunneling. It is designed to demonstrate low-level network programming, concurrency, caching, and system-level design concepts.
The proxy acts as an intermediary between clients and remote servers:
- For HTTP, it parses, forwards, caches, and logs requests.
- For HTTPS, it establishes a transparent TCP tunnel without inspecting encrypted data.
- Supports standard HTTP methods (
GET,POST, etc.) - Handles both:
- origin-form requests (
GET /path HTTP/1.1) - absolute-form requests (
GET http://host/path HTTP/1.1)
- origin-form requests (
- Normalizes host, path, and port before forwarding
- Correctly forwards request headers and bodies
- Full support for
CONNECT host:port HTTP/1.1 - Establishes a bidirectional TCP tunnel
- Compatible with browsers and
curl -x - Domain-level blocking for HTTPS requests
- Reads request bodies exactly according to
Content-Length - Prevents partial reads and protocol desynchronization
- Essential for correct handling of POST/PUT requests
- Responses are forwarded incrementally as they are received
- No requirement to buffer full responses in memory
- Enables low latency and efficient memory usage
- Thread-safe Least Recently Used (LRU) cache
- Caches only:
- HTTP
GETrequests - Successful
200 OKresponses
- HTTP
- Cache key:
- Configurable via
blocked_domains.txt - Blocks:
- HTTP requests
- HTTPS CONNECT requests
- Enforcement happens before contacting the origin server
- Structured access logs with:
- Client IP
- Host
- Path or CONNECT
- Status code
- Bytes transferred
- Timestamp
- Uses Log Rotation Strategy
- Tracks request counts per host
- Summary printed during graceful shutdown
- Thread-per-connection model
- Each client handled independently
- Shared resources protected using mutexes
- Handles
SIGINTandSIGTERM - Stops accepting new connections
- Allows active connections to complete
- Flushes logs and prints metrics summary
makeThis produces the executable proxy in the project root.
./proxyThe proxy listens on port 8000 by default.
# HTTP
curl -x http://localhost:8000 http://example.com
# HTTPS
curl -x http://localhost:8000 https://google.com
# Blocking test
curl -x http://localhost:8000 http://blocked-domain.comEdit blocked_domains.txt (project root):
facebook.com
youtube.com
Restart the proxy after changes.
Access logs are written to proxy.log or proxy.log.1 in the format:
[TIMESTAMP] CLIENT_IP HOST PATH|CONNECT STATUS_CODE BYTES_TRANSFERRED
- No HTTP/2 support
- No TLS inspection or MITM
- HTTPS responses are not cached
- No chunked request decoding