Skip to content

shubhamkumar9199/HTTPServerFromScratch-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Student HTTP Server — Assignment Project

Author: shubham kumar
Email: [email protected]

About Me

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.

Project Motivation

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.

Features

  • Written in pure Python (3.8+)
  • Serves static files: HTML, CSS, images, text
  • Accepts JSON uploads via POST /upload and saves them
  • Protects against path traversal and checks Host header
  • One thread per client for simplicity
  • Easy to run, test, and modify

How to Run

Open a terminal and run:

python server.py

Then open http://localhost:8080/ in your browser.

Project Structure

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

Example Usage

  • 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
      

Testing Tips

  • 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.

What I Learned

  • 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

Challenges

  • Making sure binary files download correctly without corruption
  • Handling errors gracefully and giving useful messages
  • Keeping the code simple but secure

Contact

If you have questions or feedback, email me at: [email protected]


About

Simple Multithreaded HTTP Server built from scratch

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published