This is a basic Multi-Threaded HTTP Server implemented from scratch in C++ with support for serving HTML, plain text, and CSS files.
- Handle multiple routes
- Implements Multi-Threading using a Thread Pool.
- Serve static HTML and CSS files
- Send plain text responses
- Clone the repository:
git clone https://github.com/shorya-1012/http_server.git
cd http-server- Build the project using CMake:
mkdir build && cd build
cmake ..
make- Run the server:
./server- Open your browser and navigate to:
http://localhost:8080/
int main(int argc, char *argv[]) {
Server server;
server.add_routes("/", [](HttpRequest &req, HttpResponse &res) {
res.send_html(200, "../templates/index.html");
});
server.add_routes("/about", [](HttpRequest &req, HttpResponse &res) {
res.send_text(200, "Welcome to About Page");
});
server.add_routes("/foo", [](HttpRequest &req, HttpResponse &res) {
res.send_text(200, "BAR");
});
server.run(8080);
return 0;
}No external dependencies. Uses only standard C++ and POSIX system calls (socket, fork, read, write, etc.).