A fully featured HTTP/1.1 server implementation with support for concurrent connections, binary file transfers, and JSON processing.
- Multi-threaded request handling with configurable thread pool
- GET and POST method support
- Binary file downloads (images, text files)
- JSON processing and file uploads
- Keep-alive connections with timeout
- Security features (path traversal protection, host validation)
- Comprehensive logging
- Python 3.7 or higher
- No external dependencies required (uses standard library)
git clone [your-repo-url]
cd [repo-directory]Start the server:
python server.py [port] [host] [thread_pool_size]Default values:
- port: 8080
- host: 127.0.0.1
- thread_pool_size: 10
Example:
python server.py 8000 0.0.0.0 20- Basic GET requests:
# Get HTML page
curl http://localhost:8080/
# Download binary file
curl -O http://localhost:8080/logo.png- POST JSON data:
curl -X POST http://localhost:8080/upload \
-H "Content-Type: application/json" \
-d '{"message": "Hello, Server!"}'- Error cases:
# Method not allowed
curl -X PUT http://localhost:8080/
# Path traversal attempt
curl http://localhost:8080/../etc/passwd
# Missing Host header
curl http://localhost:8080/ -H "Host:"- Files are read in binary mode using 4KB chunks
- Content-Type and Content-Disposition headers set appropriately
- Support for HTML, TXT, PNG, and JPEG files
- Fixed-size thread pool (configurable)
- Connection queue for handling excess requests
- Thread safety using locks and synchronization primitives
- Path traversal protection
- Host header validation
- Request size limits
- Content type validation
- Maximum request size: 8192 bytes
- Supported file types: HTML, TXT, PNG, JPEG
- Maximum 100 requests per persistent connection
- 30-second timeout for keep-alive connections
- Thread pool size is fixed after startup
This project is for educational purposes only.