A lightweight HTTP server implementation in Python using sockets and threading. This project demonstrates handling basic HTTP requests and responses from scratch.
-
Root Endpoint (
/)- Responds with a simple
200 OKmessage.
- Responds with a simple
-
Echo Endpoint (
/echo/<message>)- Returns the
<message>part of the URL as plain text.
- Returns the
-
User-Agent Endpoint (
/user-agent)- Extracts and returns the
User-Agentheader sent by the client.
- Extracts and returns the
-
404 Handling
- Any unrecognized endpoint returns
404 Not Found.
- Any unrecognized endpoint returns
-
Multi-threaded Handling
- Each client connection is processed in its own thread for concurrency.
- Python 3.7+
No external dependencies are required.
Clone the repository:
git clone https://github.com/marc-treu/codecreafter-http-server.git
cd codecreafter-http-serverRun the server:
python main.pyThe server will start listening on localhost:4221.
-
Root
curl http://localhost:4221/
-
Echo
curl http://localhost:4221/echo/hello
-
User-Agent
curl -H "User-Agent: CustomAgent" http://localhost:4221/user-agent
-
main.py
-
Implements all server logic, including:
- Request reading and parsing
- Response construction
- Threaded connection handling
-
- Minimal HTTP compliance (only handles simple GET-like requests)
- No persistent connections or advanced HTTP features
- No SSL/TLS support