A multi-threaded HTTP/1.1 web server built from scratch using only the
Python standard library (socket, threading) — no Flask, no Django, no
http.server.
- Raw TCP socket listening + HTTP/1.1 request parsing (method, path, query, headers, body)
- Router with dynamic path segments:
/api/notes/<id> - JSON API endpoints with automatic 400 on bad input
- Static file serving from
static/with MIME-type detection and../traversal protection - Correct status codes: 200 / 201 / 400 / 403 / 404 / 405 (+
Allowheader) - Thread-per-client concurrency
- Graceful shutdown via Ctrl+C
python server.py
python server.py --port 9000Http_Server/
│
├── server.py # Main server implementation
│ ├── TTLCache class # LRU cache with TTL
│ ├── RateLimiter class # Token bucket rate limiter
│ ├── HTTPRequest class # Request parser/representation
│ ├── HTTPResponse class # Response builder
│ ├── Router class # URL routing
│ ├── PyServer class # Main server
│ ├── Routes (decorators) # API endpoints
│ └── main() # Entry point
│
├── benchmark.py # Load testing tool
│ ├── raw_request() # HTTP client
│ ├── worker() # Concurrent worker
│ ├── percentile() # Statistics helper
│ └── main() # Entry point
│
├── static/ # Static file directory
│ ├── index.html # Default page
│
└── benchmark_20c.json # Generated benchmark results
| Endpoint | Description |
|---|---|
GET /api/hello?name=You |
Greeting JSON |
GET /api/info |
Server & request info |
GET /api/notes |
List notes |
POST /api/notes |
Create note — body: {"title": "...", "body": "..."} |
GET /api/notes/<id> |
Get one note |
Python Standard Library only:
| Module | Purpose |
|---|---|
socket |
Network communication |
threading |
Concurrency |
json |
API data serialization |
os |
File operations |
time |
Timing and caching |
logging |
Debugging |
argparse |
CLI argument parsing |
collections |
Data structures (OrderedDict, Counter) |
urllib |
URL parsing |
mimetypes |
MIME type detection |
statistics |
Statistical calculations |