No description
Find a file
NeroBurner bff663c407 README: update cmake commands
using cmake --build is more cross platform and independent of the used generator/compiler
2019-10-29 13:03:27 +01:00
docs Added a benchmark page as suggested in https://github.com/openjournals/joss-reviews/issues/1592#issuecomment-515900507 2019-07-31 22:21:00 +02:00
paper Update paper.bib 2019-08-26 02:25:19 +00:00
tests Deprecated Request::remote_endpoint_address() and Request::remote_endpoint_port() 2019-09-17 10:59:21 +02:00
web Added default GET-example 2014-07-11 12:43:58 +02:00
.clang-format Added SimpleWeb::Date::to_string to create HTTP date strings 2019-07-31 15:23:50 +02:00
.gitignore Added more detailed dependency installation instructions as suggested in https://github.com/openjournals/joss-reviews/issues/1592#issuecomment-515789575 2019-07-29 10:14:34 +02:00
.gitlab-ci.yml Added more detailed dependency installation instructions as suggested in https://github.com/openjournals/joss-reviews/issues/1592#issuecomment-515789575 2019-07-29 10:14:34 +02:00
asio_compatibility.hpp Cleanup of include guards 2019-06-25 11:56:21 +02:00
client_http.hpp Improved comments on public functions and variables as suggested in https://github.com/openjournals/joss-reviews/issues/1592#issuecomment-514946444 2019-07-26 09:28:20 +02:00
client_https.hpp Removed unnecessary check 2019-09-17 11:35:38 +02:00
CMakeLists.txt Removed flag -Wsign-conversion for now due to excessive warnings from boost 2019-08-26 14:11:26 +02:00
crypto.hpp Improved comments on public functions and variables as suggested in https://github.com/openjournals/joss-reviews/issues/1592#issuecomment-514946444 2019-07-26 09:28:20 +02:00
http_examples.cpp Deprecated Request::remote_endpoint_address() and Request::remote_endpoint_port() 2019-09-17 10:59:21 +02:00
https_examples.cpp Deprecated Request::remote_endpoint_address() and Request::remote_endpoint_port() 2019-09-17 10:59:21 +02:00
LICENSE Updated LICENSE year 2019-07-15 15:25:14 +02:00
mutex.hpp Improved comments on public functions and variables as suggested in https://github.com/openjournals/joss-reviews/issues/1592#issuecomment-514946444 2019-07-26 09:28:20 +02:00
README.md README: update cmake commands 2019-10-29 13:03:27 +01:00
server_http.hpp Deprecated Request::remote_endpoint_address() and Request::remote_endpoint_port() 2019-09-17 10:59:21 +02:00
server_https.hpp Improved comments on public functions and variables as suggested in https://github.com/openjournals/joss-reviews/issues/1592#issuecomment-514946444 2019-07-26 09:28:20 +02:00
status_code.hpp Fixes #261: SimpleWeb::status_code(const std::string &) now only regards the status code number when searching for status code enum, and can also return undefined enums that can be cast to an integer value 2019-04-29 13:30:22 +02:00
utility.hpp fixes compile error with MinGW. 2019-09-30 14:19:23 +02:00

Simple-Web-Server

A 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.

See 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.

Features

  • Asynchronous request handling
  • Thread pool if needed
  • Platform independent
  • HTTP/1.1 supported, including persistent connections
  • HTTPS supported
  • Chunked transfer encoding and server-sent events
  • Can set timeouts for request/response and content
  • Can set max request/response size
  • Sending outgoing messages is thread safe
  • Client creates necessary connections and perform reconnects when needed

See also benchmarks for a performance comparisons to a few other HTTP libraries.

Usage

See http_examples.cpp or https_examples.cpp for example usage. The following server resources are setup using regular expressions to match request paths:

  • POST /string - responds with the posted string.
  • POST /json - parses the request content as JSON, and responds with some of the parsed values.
  • GET /info - responds with information extracted from the request.
  • GET /match/([0-9]+) - matches for instance /match/123 and responds with the matched number 123.
  • GET /work - starts a thread, simulating heavy work, and responds when the work is done.
  • GET - a special default_resource handler is called when a request path does not match any of the above resources. This resource responds with the content of files in the web/-folder if the request path identifies one of these files.

Documentation is also available, generated from the master branch.

Dependencies

  • Boost.Asio or standalone Asio
  • Boost is required to compile the examples
  • For HTTPS: OpenSSL libraries

Installation instructions for the dependencies needed to compile the examples on a selection of platforms can be seen below. Default build with Boost.Asio is assumed. Turn on CMake option USE_STANDALONE_ASIO to instead use standalone Asio.

Debian based distributions

sudo apt-get install libssl-dev libboost-filesystem-dev libboost-thread-dev

Arch Linux based distributions

sudo pacman -S boost

MacOS

brew install openssl boost

Compile and run

Compile with a C++11 compliant compiler:

cmake -H. -Bbuild
cmake --build build

HTTP

Run the server and client examples: ./build/http_examples

Direct your favorite browser to for instance http://localhost:8080/

HTTPS

Before running the server, an RSA private key (server.key) and an SSL certificate (server.crt) must be created.

Run the server and client examples: ./build/https_examples

Direct your favorite browser to for instance https://localhost:8080/

Contributing

Contributions are welcome, either by creating an issue or a merge request. However, before you create a new issue or merge request, please search for previous similar issues or requests. A response will normally be given within a few days.