A Python-based multithreaded proxy server that supports both HTTP and HTTPS traffic, implements caching, domain blocking, and provides a management console for runtime control and statistics.
The proxy listens locally and forwards browser traffic to destination servers while optionally caching responses and filtering requests.
- Handles standard HTTP requests (
GET,POST, etc.). - Supports HTTPS tunneling using the
CONNECTmethod. - HTTPS traffic is securely forwarded between client and server.
- Uses a thread pool to handle multiple clients concurrently.
- Default pool size: 20 worker threads.
The proxy caches HTTP responses to improve performance.
Cache properties:
| Property | Value |
|---|---|
| TTL | 60 seconds |
| Max cache entries | 50 |
| Max object size | 1 MB |
Cached responses are served instantly when valid.
A blocklist allows preventing access to specific hosts.
Example blocked response:
HTTP/1.1 403 Forbidden
Blocked by proxy.
A built-in console allows live proxy control while the server is running.
Supported commands:
| Command | Description |
|---|---|
block <host> |
Block a domain |
unblock <host> |
Remove domain from blocklist |
show blocklist |
Display blocked domains |
show cache |
List cached responses |
clear cache |
Clear all cached entries |
stats |
Show cache hit/miss statistics |
help |
Show all commands |
All HTTP requests are logged to:
timing_log.txt
Each entry records:
timestamp, HIT/MISS, response_time, url
Statistics can be viewed via the stats command.
Example metrics:
- Cache hit rate
- Average response time
- Speedup from caching
The proxy consists of the following components:
Client Browser
│
▼
TCPServer
│
▼
Request_Parser
│
┌───────────────┐
▼ ▼
Http_Handler Https_Handler
│ │
▼ ▼
Cache Tunnel traffic
│
▼
Origin Server
| Class | Responsibility |
|---|---|
TCPServer |
Accepts client connections and distributes them to worker threads |
Request_Parser |
Extracts method, host, port, and path from client requests |
Http_Handler |
Processes HTTP requests and manages caching |
Https_Handler |
Creates encrypted tunnels for HTTPS traffic |
Management_Console |
Provides runtime proxy management |
Requirements:
Python 3.8+
Clone the repository:
git clone https://github.com/yourusername/proxy-server
cd proxy-serverStart the proxy server:
python proxy.pyExpected output:
[PROXY] Listening on 127.0.0.1:8888
[PROXY] Set your browser proxy to 127.0.0.1:8888
[CONSOLE] Management console ready. Type 'help' for commands.
Set your browser proxy settings to:
Host: 127.0.0.1
Port: 8888
Example locations:
Settings → System → Open Proxy Settings
Settings → Network Settings → Manual Proxy Configuration
[12:03:44] 127.0.0.1 — GET example.com/index.html
[CACHE MISS] example.com/index.html — fetched in 0.2443s (12438 bytes)
[12:03:50] 127.0.0.1 — GET example.com/index.html
[CACHE HIT ] example.com/index.html — served in 0.0002s (age 6s)
── Cache Statistics ──────────────────────
Total requests : 20
Cache hits : 12 (60%)
Cache misses : 8 (40%)
Avg HIT time : 0.0003s
Avg MISS time : 0.2011s
Cache is 670x faster than origin
──────────────────────────────────────────