A minimal HTTP/1.1 server implemented from scratch in Rust using raw TCP sockets.
- Manual HTTP/1.1 request parsing
- Manual response construction
- Thread-per-connection concurrency
- Persistent connections (keep-alive)
- Gzip compression (when
Accept-Encoding: gzipis sent) - Static file serving
- File upload via POST
- Content-Length handling
- Proper CRLF formatting
| Route | Method | Description |
|---|---|---|
/ |
GET | Returns 200 OK |
/echo/{text} |
GET | Returns {text} |
/user-agent |
GET | Returns the User-Agent header |
/files/{filename} |
GET | Serves file from directory |
/files/{filename} |
POST | Writes body to file |
Unknown routes return 404 Not Found.
Start the server:
cargo runServe files from a directory:
cargo run -- --directory ./publicServer runs on:
127.0.0.1:4221
curl http://localhost:4221/echo/hello
curl -X POST --data "data" http://localhost:4221/files/test.txt
curl -H "Accept-Encoding: gzip" http://localhost:4221/echo/hello.
├── main.rs
├── server.rs
├── handlers.rs
├── utils.rs
└── http/
├── request.rs
└── response.rs
Run tests:
cargo testThis project was built to understand TCP networking and HTTP/1.1 internals by implementing a server without external frameworks.
Challenge by CodeCrafters: https://codecrafters.io
MIT License — see the LICENSE file.