Author: shubham kumar
Email: [email protected]
I'm shubham kumar, a student passionate about learning how computers communicate and how web servers work. This project was built for my College assignment to demonstrate my understanding of socket programming, HTTP, and basic web security.
I wanted to create a simple, easy-to-understand HTTP server from scratch using Python. My goal was to learn how real servers handle requests, serve files, and keep things secure. I focused on clarity and practical features, so anyone can read and use my code.
- Written in pure Python (3.8+)
- Serves static files: HTML, CSS, images, text
- Accepts JSON uploads via POST
/uploadand saves them - Protects against path traversal and checks Host header
- One thread per client for simplicity
- Easy to run, test, and modify
Open a terminal and run:
python server.py
Then open http://localhost:8080/ in your browser.
project/
├── server.py # Main server script
├── README.md # This file
├── .gitignore
├── requirements.txt
├── resources/
│ ├── index.html # Homepage
│ ├── about.html # About the project
│ ├── contact.html # My contact info
│ ├── style.css # Shared CSS
│ ├── sample.txt # Text file for download
│ ├── logo.png # PNG image
│ ├── photo.jpg # JPEG image
│ └── uploads/ # Where POSTed JSON files are saved
└── tests/
└── sample_post.json # Example JSON for POST
- Download a file:
- POST a JSON file:
- Use curl:
curl -v -X POST http://localhost:8080/upload -H "Content-Type: application/json" -d @tests/sample_post.json
- Use curl:
- Try downloading images and text files from the homepage.
- Use the provided sample JSON to test POST uploads.
- Check the
resources/uploads/folder to see your uploaded files. - If you get a 404 or 415 error, check your file path or type.
- How to use Python sockets to accept connections and read HTTP requests
- How to parse headers and serve different file types
- How to protect against common security issues (like path traversal)
- How to handle multiple clients with threads
- How to write clear, maintainable code and document my work
- Making sure binary files download correctly without corruption
- Handling errors gracefully and giving useful messages
- Keeping the code simple but secure
If you have questions or feedback, email me at: [email protected]