Skip to content

prodmatze/based-http-server-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🖥️ Based HTTP Server (Python)

This project is a fully working HTTP/1.1 server built from scratch using only Python sockets.


📋 Features

  • Accepts multiple concurrent TCP connections (threaded server)
  • Handles basic GET and POST requests
  • Supports file serving from a directory
  • Supports gzip compression (Content-Encoding: gzip) if requested
  • Handles persistent connections (Connection: keep-alive)
  • Cleanly closes connections when Connection: close header is received
  • Parses incoming HTTP requests manually (no external libraries)
  • Dynamically generates appropriate HTTP responses

🚀 How to Run Locally

# Clone this repository
git clone https://github.com/prodmatze/based-http-server-python.git
cd based-http-server-python

# Run the server
python3 app/main.py

The server will listen on localhost:4221.


🧪 Example Usage

Basic GET request:

curl http://localhost:4221/

Echo endpoint:

curl http://localhost:4221/echo/hello
# Response: "hello"

User-Agent endpoint:

curl -A "my-custom-agent" http://localhost:4221/user-agent
# Response: "my-custom-agent"

File download:

curl http://localhost:4221/files/filename.txt

Request gzip compressed response:

curl --compressed http://localhost:4221/echo/hello

Persistent connections:

curl --keepalive-time 60 http://localhost:4221/echo/keepalive

🛠️ Technologies Used

  • Python 3
  • Standard Library only (socket, threading, gzip, os)

✨ Future Improvements (Optional)

  • Better parsing to support HTTP/1.0 and HTTP/2.0 versions
  • Support for additional HTTP methods (PUT, DELETE)
  • Improved error handling for file operations
  • Timeout handling for idle persistent connections
  • Refactor project-structure a little (seperate Class for response, etc)

This project was created as part of the Codecrafters.io "Build Your Own HTTP Server" challenge, where the goal was to reimplement core HTTP server functionality step-by-step.

About

My implementation of a basic HTTP server in Python, built from scratch.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages