A simple HTTP server in C with:
- static resources
- in-memory dynamic resources
- optional distributed lookup/routing over a small DHT ring
- GCC or Clang
- CMake ≥ 3.5
- Python 3 + pip (for tests)
- POSIX-compatible OS (Linux, macOS)
cmake -B build && make -C buildThe binary is placed at build/webserver.
Install the test dependencies once:
pip install -r requirements.txt./build/webserver <hostname> <port>Example — listen on all interfaces, port 8080:
./build/webserver 0.0.0.0 8080Example — localhost only:
./build/webserver 127.0.0.1 4000PRED_ID=<id> PRED_IP=<ip> PRED_PORT=<port> \
SUCC_ID=<id> SUCC_IP=<ip> SUCC_PORT=<port> \
./build/webserver <hostname> <port> <node-id>Example 3-node ring:
PRED_ID=50000 PRED_IP=127.0.0.1 PRED_PORT=4002 \
SUCC_ID=20000 SUCC_IP=127.0.0.1 SUCC_PORT=4001 \
./build/webserver 127.0.0.1 4000 0PRED_ID=0 PRED_IP=127.0.0.1 PRED_PORT=4000 \
SUCC_ID=50000 SUCC_IP=127.0.0.1 SUCC_PORT=4002 \
./build/webserver 127.0.0.1 4001 20000PRED_ID=20000 PRED_IP=127.0.0.1 PRED_PORT=4001 \
SUCC_ID=0 SUCC_IP=127.0.0.1 SUCC_PORT=4000 \
./build/webserver 127.0.0.1 4002 50000| Method | Path | Response |
|---|---|---|
GET |
/static/foo |
200 Foo |
GET |
/static/bar |
200 Bar |
GET |
/static/baz |
200 Baz |
| Method | Path | Behaviour |
|---|---|---|
PUT |
/dynamic/<name> |
Creates the resource (201) or updates it (204) |
GET |
/dynamic/<name> |
Returns the stored content (200) or 404 |
DELETE |
/dynamic/<name> |
Deletes the resource (204) or 404 if not found |
Attempting PUT or DELETE on a non-/dynamic/ path returns 403.
Any other HTTP method returns 501.
# Create a resource
curl -i -X PUT http://127.0.0.1:4000/dynamic/hello \
-H "Content-Length: 11" \
-d "hello world"
# Read it back
curl -i http://127.0.0.1:4000/dynamic/hello
# Update it
curl -i -X PUT http://127.0.0.1:4000/dynamic/hello \
-H "Content-Length: 5" \
-d "world"
# Delete it
curl -i -X DELETE http://127.0.0.1:4000/dynamic/hello
# Static resource
curl -i http://127.0.0.1:4000/static/foocurl -i -X PUT http://127.0.0.1:4000/dynamic/hello \
-d "hello world"
curl -i -L http://127.0.0.1:4000/dynamic/hello- Dynamic resources are stored in memory only and are lost when the server stops.
- In DHT mode, a node stores a dynamic resource only if it is responsible for that resource.
- DHT lookups are performed over UDP.
- Only one TCP client is handled at a time.
BUFFER_SIZEis set to1024bytes innetworking.h. Larger requests are received across multiplerecvcalls and reassembled.