This project is a zero-dependency HTTP/1.1 static file server written in Python using only the standard library. It listens on a raw TCP socket, accepts concurrent client connections, parses raw HTTP request bytes, and serves files from a local directory without any third-party packages.
The server is intentionally small but realistic: it supports standard GET and HEAD requests, serves static files and directory indexes, and responds cleanly to browsers and command-line clients such as curl and nc.
8080public by default)200 OK, 403 Forbidden, 404 Not Found, and 405 Method Not AllowedcurlThis project intentionally targets a pragmatic subset of HTTP/1.1:
GET and HEAD methodsContent-Length parsingConnection: closeserver.py: standalone entry point, CLI flag parsing, socket setup, request loop, routing logic, and response formattingpublic/: example static content served by the serversocket.AF_INET and socket.SOCK_STREAMbytearraySocket Read -> Byte Buffer Parsing -> Handler Dispatch -> Raw Response Framing
Detailed flow:
recv() fills a buffer with raw bytes from the client socket\r\n\r\n)Content-Length header is present, the parser continues reading until the full body is availableRequestResponse object is converted to bytes using the HTTP status line, headers, and body framingsendall() transmits the response back to the clientZero_dep_hack/
├── README.md
├── STDLIB.md
├── server.py
└── public/
└── index.html
No requirements.txt or package manifest is included because the project is intentionally zero-dependency.
The runnable implementation is in server.py. It includes:
argparse CLI configurationcd /path/to/Zero_dep_hack
python3 server.py --host 127.0.0.1 --port 8080 --directory public
curl -i http://127.0.0.1:8080/
Expected outcome:
200 OKpublic/index.htmlContent-Length and Connection: closecurl -I http://127.0.0.1:8080/
curl -i http://127.0.0.1:8080/does-not-exist.html
Expected outcome: 404 Not Found
nc 127.0.0.1 8080
GET / HTTP/1.1
Host: localhost
The server will respond with a valid HTTP/1.1 message.
Press Ctrl+C in the terminal running the Python process.
This implementation is designed to be idiomatic, robust, and clearly aligned with the Track C requirements: no third-party dependencies, explicit concurrency, direct socket handling, and clean CLI execution.