xref: /aosp_15_r20/external/ot-br-posix/third_party/Simple-web-server/repo/README.md (revision 4a64e381480ef79f0532b2421e44e6ee336b8e0d)
1*4a64e381SAndroid Build Coastguard Worker# Simple-Web-Server
2*4a64e381SAndroid Build Coastguard Worker
3*4a64e381SAndroid Build Coastguard WorkerA very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Asio (both Boost.Asio and standalone Asio can be used). Created to be an easy way to make REST resources available from C++ applications.
4*4a64e381SAndroid Build Coastguard Worker
5*4a64e381SAndroid Build Coastguard WorkerSee https://gitlab.com/eidheim/Simple-WebSocket-Server for an easy way to make WebSocket/WebSocket Secure endpoints in C++. Also, feel free to check out the new C++ IDE supporting C++11/14/17: https://gitlab.com/cppit/jucipp.
6*4a64e381SAndroid Build Coastguard Worker
7*4a64e381SAndroid Build Coastguard Worker## Features
8*4a64e381SAndroid Build Coastguard Worker
9*4a64e381SAndroid Build Coastguard Worker* Asynchronous request handling
10*4a64e381SAndroid Build Coastguard Worker* Thread pool if needed
11*4a64e381SAndroid Build Coastguard Worker* Platform independent
12*4a64e381SAndroid Build Coastguard Worker* HTTP/1.1 supported, including persistent connections
13*4a64e381SAndroid Build Coastguard Worker* HTTPS supported
14*4a64e381SAndroid Build Coastguard Worker* Chunked transfer encoding and server-sent events
15*4a64e381SAndroid Build Coastguard Worker* Can set timeouts for request/response and content
16*4a64e381SAndroid Build Coastguard Worker* Can set max request/response size
17*4a64e381SAndroid Build Coastguard Worker* Sending outgoing messages is thread safe
18*4a64e381SAndroid Build Coastguard Worker* Client creates necessary connections and perform reconnects when needed
19*4a64e381SAndroid Build Coastguard Worker
20*4a64e381SAndroid Build Coastguard WorkerSee also [benchmarks](https://gitlab.com/eidheim/Simple-Web-Server/blob/master/docs/benchmarks.md) for a performance comparisons to a few other HTTP libraries.
21*4a64e381SAndroid Build Coastguard Worker
22*4a64e381SAndroid Build Coastguard Worker## Usage
23*4a64e381SAndroid Build Coastguard Worker
24*4a64e381SAndroid Build Coastguard WorkerSee [http_examples.cpp](https://gitlab.com/eidheim/Simple-Web-Server/blob/master/http_examples.cpp) or
25*4a64e381SAndroid Build Coastguard Worker[https_examples.cpp](https://gitlab.com/eidheim/Simple-Web-Server/blob/master/https_examples.cpp) for example usage.
26*4a64e381SAndroid Build Coastguard WorkerThe following server resources are setup using regular expressions to match request paths:
27*4a64e381SAndroid Build Coastguard Worker* `POST /string` - responds with the posted string.
28*4a64e381SAndroid Build Coastguard Worker* `POST /json` - parses the request content as JSON, and responds with some of the parsed values.
29*4a64e381SAndroid Build Coastguard Worker* `GET /info` - responds with information extracted from the request.
30*4a64e381SAndroid Build Coastguard Worker* `GET /match/([0-9]+)` - matches for instance `/match/123` and responds with the matched number `123`.
31*4a64e381SAndroid Build Coastguard Worker* `GET /work` - starts a thread, simulating heavy work, and responds when the work is done.
32*4a64e381SAndroid Build Coastguard Worker* `GET` - a special default_resource handler is called when a request path does not match any of the above resources.
33*4a64e381SAndroid Build Coastguard WorkerThis resource responds with the content of files in the `web/`-folder if the request path identifies one of these files.
34*4a64e381SAndroid Build Coastguard Worker
35*4a64e381SAndroid Build Coastguard Worker[Documentation](https://eidheim.gitlab.io/Simple-Web-Server/annotated.html) is also available, generated from the master branch.
36*4a64e381SAndroid Build Coastguard Worker
37*4a64e381SAndroid Build Coastguard Worker## Dependencies
38*4a64e381SAndroid Build Coastguard Worker
39*4a64e381SAndroid Build Coastguard Worker* Boost.Asio or standalone Asio
40*4a64e381SAndroid Build Coastguard Worker* Boost is required to compile the examples
41*4a64e381SAndroid Build Coastguard Worker* For HTTPS: OpenSSL libraries
42*4a64e381SAndroid Build Coastguard Worker
43*4a64e381SAndroid Build Coastguard WorkerInstallation instructions for the dependencies needed to compile the examples on a selection of platforms can be seen below.
44*4a64e381SAndroid Build Coastguard WorkerDefault build with Boost.Asio is assumed. Turn on CMake option `USE_STANDALONE_ASIO` to instead use standalone Asio.
45*4a64e381SAndroid Build Coastguard Worker
46*4a64e381SAndroid Build Coastguard Worker### Debian based distributions
47*4a64e381SAndroid Build Coastguard Worker
48*4a64e381SAndroid Build Coastguard Worker```sh
49*4a64e381SAndroid Build Coastguard Workersudo apt-get install libssl-dev libboost-filesystem-dev libboost-thread-dev
50*4a64e381SAndroid Build Coastguard Worker```
51*4a64e381SAndroid Build Coastguard Worker
52*4a64e381SAndroid Build Coastguard Worker### Arch Linux based distributions
53*4a64e381SAndroid Build Coastguard Worker
54*4a64e381SAndroid Build Coastguard Worker```sh
55*4a64e381SAndroid Build Coastguard Workersudo pacman -S boost
56*4a64e381SAndroid Build Coastguard Worker```
57*4a64e381SAndroid Build Coastguard Worker
58*4a64e381SAndroid Build Coastguard Worker### MacOS
59*4a64e381SAndroid Build Coastguard Worker
60*4a64e381SAndroid Build Coastguard Worker```sh
61*4a64e381SAndroid Build Coastguard Workerbrew install openssl boost
62*4a64e381SAndroid Build Coastguard Worker```
63*4a64e381SAndroid Build Coastguard Worker
64*4a64e381SAndroid Build Coastguard Worker## Compile and run
65*4a64e381SAndroid Build Coastguard Worker
66*4a64e381SAndroid Build Coastguard WorkerCompile with a C++11 compliant compiler:
67*4a64e381SAndroid Build Coastguard Worker```sh
68*4a64e381SAndroid Build Coastguard Workercmake -H. -Bbuild
69*4a64e381SAndroid Build Coastguard Workercmake --build build
70*4a64e381SAndroid Build Coastguard Worker```
71*4a64e381SAndroid Build Coastguard Worker
72*4a64e381SAndroid Build Coastguard Worker### HTTP
73*4a64e381SAndroid Build Coastguard Worker
74*4a64e381SAndroid Build Coastguard WorkerRun the server and client examples: `./build/http_examples`
75*4a64e381SAndroid Build Coastguard Worker
76*4a64e381SAndroid Build Coastguard WorkerDirect your favorite browser to for instance http://localhost:8080/
77*4a64e381SAndroid Build Coastguard Worker
78*4a64e381SAndroid Build Coastguard Worker### HTTPS
79*4a64e381SAndroid Build Coastguard Worker
80*4a64e381SAndroid Build Coastguard WorkerBefore running the server, an RSA private key (server.key) and an SSL certificate (server.crt) must be created.
81*4a64e381SAndroid Build Coastguard Worker
82*4a64e381SAndroid Build Coastguard WorkerRun the server and client examples: `./build/https_examples`
83*4a64e381SAndroid Build Coastguard Worker
84*4a64e381SAndroid Build Coastguard WorkerDirect your favorite browser to for instance https://localhost:8080/
85*4a64e381SAndroid Build Coastguard Worker
86*4a64e381SAndroid Build Coastguard Worker## Contributing
87*4a64e381SAndroid Build Coastguard Worker
88*4a64e381SAndroid Build Coastguard WorkerContributions are welcome, either by creating an issue or a merge request.
89*4a64e381SAndroid Build Coastguard WorkerHowever, before you create a new issue or merge request, please search for previous similar issues or requests.
90*4a64e381SAndroid Build Coastguard WorkerA response will normally be given within a few days.
91