This project is a fully working HTTP/1.1 server built from scratch using only Python sockets.
- Accepts multiple concurrent TCP connections (threaded server)
- Handles basic
GETandPOSTrequests - 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: closeheader is received - Parses incoming HTTP requests manually (no external libraries)
- Dynamically generates appropriate HTTP responses
# 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.pyThe server will listen on localhost:4221.
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.txtRequest gzip compressed response:
curl --compressed http://localhost:4221/echo/helloPersistent connections:
curl --keepalive-time 60 http://localhost:4221/echo/keepalive- Python 3
- Standard Library only (
socket,threading,gzip,os)
- 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)