Yet another HTTP server implemented in C++.
https://github.com/songquanpeng/http-server.git
Yet another HTTP server implemented in C++
$ uname -r
5.10.16.3-microsoft-standard-WSL2
$ sudo apt install build-essential cmake
$ cmake --version
cmake version 3.22.1
$ gcc --version
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
# or
cmake .. -DCMAKE_BUILD_TYPE=Release
make
./server
C++
EventLoop loop_;
HTTPServer server(&loop_, 3000, 4);
%%CODEBLOCK3%%C++
void getEchoPage(const HTTPRequestPtr &req, const HTTPResponsePtr &res) {
res->send("<li> Method: " + req->method + "</li><li> URL: " + req->url + "</li>");
}
%%CODEBLOCK4%%C++
server.setRoute("/", getIndexPage);
server.setRoute("/echo", getEchoPage);
server.serveStatic("/public");
%%CODEBLOCK5%%C++
server.start();
loop_.loop_();
%%CODEBLOCK6%%shell
wget https://github.com/justsong-lab/WebBench/releases/download/v0.1.0/webbench
chmod u+x webbench
./webbench -c 100 -t 5 http://localhost:3000/
``