This is a simple multi-threaded HTTP server implemented in Python for a Computer Networks project. It serves static files from the resources directory and supports file uploads via POST requests.
- Multi-threaded architecture with a fixed-size thread pool
- Supports GET requests for static files (HTML, TXT, PNG, JPG, JPEG)
- Supports POST requests to
/uploadfor JSON data - Keep-alive connections
- Security features: path traversal protection, host validation, content-type checks
- Logging of requests and responses
- Python 3.x
Clone or download the project files.
No build required. This is a pure Python script using only standard library modules. Ensure Python 3.x is installed.
Run the server with default settings:
python server.py
Or specify host, port, and number of threads:
python server.py [port] [host] [threads]
For example:
python server.py 8080 127.0.0.1 10
Prerequisites: Ensure the resources directory exists (it will be created automatically if missing). To stop the server, press Ctrl+C. Test the server by opening http://127.0.0.1:8080 in a browser or using curl for API endpoints.
A simplified overview of the server's request handling flow:
Client Request
|
v
Accept Connection (Main Loop)
|
v
Queue to Thread Pool
|
v
Parse & Validate Request (Host, Path, Security)
|
v
Handle Request:
- GET: Serve Static File
- POST: Upload JSON to /upload
|
v
Send Response (Headers + Body)
|
v
Log & Manage Connection (Keep-Alive or Close)
For a detailed architecture diagram, see project_summary.md.
server.py: Main server scriptresources/: Directory containing static filesindex.html: Home pageabout.html: About pagecontact.html: Contact pagesample.txt: Sample text filelogo.png: Logo imagephoto.jpg: Photo imageuploads/: Directory for uploaded files
- GET / : Serves index.html
- GET / : Serves static files
- POST /upload : Accepts JSON data and saves to uploads/
None specified.