๐Ÿ“ฆ songquanpeng / http-server

Yet another HTTP server implemented in C++.

โ˜… 1 stars โ‘‚ 0 forks ๐Ÿ‘ 1 watching
๐Ÿ“ฅ Clone https://github.com/songquanpeng/http-server.git
HTTPS git clone https://github.com/songquanpeng/http-server.git
SSH git clone git@github.com:songquanpeng/http-server.git
CLI gh repo clone songquanpeng/http-server
JustSong JustSong :book: Update readme 3d6d95f 3 years ago ๐Ÿ“ History
๐Ÿ“‚ main View all commits โ†’
๐Ÿ“ .github
๐Ÿ“ core
๐Ÿ“„ .gitignore
๐Ÿ“„ CMakeLists.txt
๐Ÿ“„ main.cpp
๐Ÿ“„ README.md
๐Ÿ“„ README.md

HTTP Server

Yet another HTTP server implemented in C++

Running Steps

  • Prepare environments:
$ 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
  • Build executables:
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
# or
cmake .. -DCMAKE_BUILD_TYPE=Release
make
  • Start the server:
./server

Basic Usages

Please refer main.cpp for details.
  • Initialize server & event loop_:
``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/ ``