A minimal, POSIX-socket-based HTTP/1.1 server written in C++.
Supports basic routing, static file serving from a specified directory, and file upload via POST.
-
GET /
Returns a200 OKwith an empty body. -
GET /echo/{text}
Returns200 OKwith a plain-text body of{text}. -
GET /user-agent
Returns200 OKwith yourUser-Agentheader value. -
GET /files/{filename}
Serves the file named{filename}from a user-specified directory (via--directory).- If the file exists:
HTTP/1.1 200 OK Content-Type: application/octet-stream Content-Length: <size> <raw file bytes>
- If not found, returns
404 Not Found.
- If the file exists:
-
POST /files/{filename}
Creates or overwrites{filename}in the same directory, writing the raw request body.- On success:
HTTP/1.1 201 Created Content-Length: 0
- On failure, returns
404 Not Foundor500 Internal Server Erroras appropriate.
- On success:
- Linux, macOS, or any POSIX-compatible OS
- A C++17-compatible compiler (e.g.
g++,clang++)
git clone https://github.com/<your-username>/simple-cpp-http-server.git
cd simple-cpp-http-server
# Build:
g++ -std=c++17 -pthread -o http-server src/server.cpp