No description
Find a file
2015-09-04 18:01:16 +02:00
test Changed Request::remote_endpoint_address to std::string. Modified parse_request too keep case of header parameters. 2015-06-27 11:30:20 +02:00
web Added default GET-example 2014-07-11 12:43:58 +02:00
client_http.hpp Added custom response stream and possibility to flush response to clients synchronously and asynchronously. Various speed ups, including reduced use of regex and preprocessing of regex objects. boost::asio::ip::tcp::no_delay is now turned on for both Client and Server. Note: Not backward compatible with earlier versions. 2015-02-20 11:14:39 +01:00
client_https.hpp Added custom response stream and possibility to flush response to clients synchronously and asynchronously. Various speed ups, including reduced use of regex and preprocessing of regex objects. boost::asio::ip::tcp::no_delay is now turned on for both Client and Server. Note: Not backward compatible with earlier versions. 2015-02-20 11:14:39 +01:00
CMakeLists.txt Now closes file if connection is interrupted in default_resource example. Also some minor cleanup. 2015-09-02 21:02:06 +02:00
http_examples.cpp Moved strand to ServerBase. 2015-09-04 18:01:16 +02:00
https_examples.cpp Moved strand to ServerBase. 2015-09-04 18:01:16 +02:00
LICENSE Update LICENSE 2014-07-05 20:05:52 +02:00
README.md Removed async_flush and its likely erroneous code. 2015-09-02 19:55:20 +02:00
server_http.hpp Moved strand to ServerBase. 2015-09-04 18:01:16 +02:00
server_https.hpp Added custom response stream and possibility to flush response to clients synchronously and asynchronously. Various speed ups, including reduced use of regex and preprocessing of regex objects. boost::asio::ip::tcp::no_delay is now turned on for both Client and Server. Note: Not backward compatible with earlier versions. 2015-02-20 11:14:39 +01:00

Simple-Web-Server

A very simple, fast, multithreaded, platform independent HTTP and HTTPS server and client library implemented using C++11 and Boost.Asio. Created to be an easy way to make REST resources available from C++ applications.

See also https://github.com/eidheim/Simple-WebSocket-Server for an easy way to make WebSocket/WebSocket Secure endpoints in C++.

Features

  • Thread pool
  • Platform independent
  • HTTPS support
  • HTTP persistent connection (for HTTP/1.1)
  • Client supports chunked transfer encoding
  • Timeouts, if any of Server::timeout_request and Server::timeout_content are >0 (default: Server::timeout_request=5 seconds, and Server::timeout_content=300 seconds)
  • Simple way to add REST resources using regex for path, and anonymous functions
  • Possibility to flush response to clients synchronously (Server::flush).

###Usage

See http_examples.cpp or https_examples.cpp for example usage.

See particularly the JSON-POST (using Boost.PropertyTree) and the GET /match/[number] examples, which are most relevant.

The default_resource includes example use of Server::flush.

Dependencies

Boost C++ libraries must be installed, go to http://www.boost.org for download and instructions.

For HTTPS: OpenSSL libraries from https://www.openssl.org are required.

Compile and run

Compile with a C++11 compiler supporting regex (for instance g++ 4.9):

On Linux using g++: add -pthread

Note: added -lboost_filesystem for the default_resource example, and -lboost_thread to make the json-example thread safe. Also added -lboost_coroutine -lboost_context to make synchronous flushing of response stream work. On some systems you might have to use postfix -mt to link to these libraries.

You can now also compile using CMake and make:

cmake .
make

HTTP

g++ -O3 -std=c++11 http_examples.cpp -lboost_system -lboost_thread -lboost_coroutine -lboost_context -lboost_filesystem -o http_examples

Then to run the server and client examples: ./http_examples

Also, direct your favorite browser to for instance http://localhost:8080/

HTTPS

g++ -O3 -std=c++11 https_examples.cpp -lboost_system -lboost_thread -lboost_coroutine -lboost_context -lboost_filesystem -lssl -lcrypto -o https_examples

Before running the server, an RSA private key (server.key) and an SSL certificate (server.crt) must be created. Follow, for instance, the instructions given here (for a self-signed certificate): http://www.akadia.com/services/ssh_test_certificate.html

Then to run the server and client examples: ./https_examples

Also, direct your favorite browser to for instance https://localhost:8080/