HTTP/1.1 file server that reads and writes files on disk via GET and PUT. The server can run single-threaded or with a worker pool and serializes conflicting file access per-URI.
- Requirements: POSIX environment with
clang/gcc,make, and pthreads. - From the repo root run
maketo produce the./httpserverbinary. Usemake cleanto remove build artifacts.
./httpserver [-p threads] <port> [data-dir]
portmust be 1–65535.data-diris the directory to serve from; defaults to the current directory. Tests setTEST_TMPDIRto override this path automatically.-p threadsenables a thread pool to handle connections concurrently. Each request is still guarded by a per-URI mutex to prevent conflicting reads/writes on the same path.- Stop with Ctrl+C.
Example:
./httpserver -p 4 8080 ./data
- Supported methods:
GETandPUTonly. Others return501 Not Implemented. - Protocol: only
HTTP/1.1is accepted; other versions return505 Version Not Supported. - URIs: must start with
/and contain 1–63 characters ofA–Z,a–z,0–9,-, or.. Directory traversal is not allowed; the URI maps directly to a file underdata-dir. - Headers:
Content-Lengthis required forPUT; its value must be a non-negative integer.- Optional
Request-IDheader is logged when present.
GET /path200 OKwith file bytes in the body when readable.404 Not Foundif the file is missing.403 Forbiddenif the path is a directory or not readable.
PUT /pathwith a body sized byContent-Length201 Createdwhen the file did not previously exist.200 OKwhen overwriting an existing, writable file.403 Forbiddenwhen the target exists but is not writable.
- Generic failures return
400 Bad Requestfor malformed input or500 Internal Server Errorfor unexpected errors. Error responses include a short text body.
Audit logs are written to stderr in CSV form:
<METHOD>,<URI>,<status>,<Request-ID>
Request-ID is 0 when the header is absent.
- Module statuses are tracked in
tests/test-config.txt(all modules are currently markedDONE). - Run the full suite with
./tests/run_test.shfrom the repo root. The script compiles objects intoobj/ci, setsTEST_TMPDIRfor isolated I/O, and exercises parser, file, dispatcher, logging, server, connection, parallel, and main routines.