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.

This commit is contained in:
eidheim 2015-02-20 11:14:39 +01:00
commit a6154c7c5b
8 changed files with 331 additions and 168 deletions

View file

@ -13,14 +13,19 @@ See also https://github.com/eidheim/Simple-WebSocket-Server for an easy way to m
* 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
* Simple way to add REST resources using for instance regex for path, and anonymous functions
* Possibility to flush response to clients both synchronously (Server::flush) and asynchronously (Server::async_flush).
###Usage
Note: newest version is NOT backward compatible with earlier versions.
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. Note that Server::async_flush might be slightly slower than Server::flush unless you need to process computationally expensive tasks while simultaneously sending large datasets to a client.
### Dependencies
Boost C++ libraries must be installed, go to http://www.boost.org for download and instructions.
@ -33,7 +38,7 @@ Compile with a C++11 compiler supporting regex (for instance g++ 4.9):
On Linux using g++: add `-pthread`
Note: added `-lboost_thread` to make the json-example thread safe. On some systems you might have to use `-lboost_thread-mt` instead.
Note: added `-lboost_thread` to make the json-example thread safe. Also added `-lboost_coroutine -lboost_context` to make synchronous and asynchronous 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:
@ -44,7 +49,7 @@ make
#### HTTP
`g++ -O3 -std=c++11 http_examples.cpp -lboost_system -lboost_thread -o http_examples`
`g++ -O3 -std=c++11 http_examples.cpp -lboost_system -lboost_thread -lboost_coroutine -lboost_context -o http_examples`
Then to run the server and client examples: `./http_examples`
@ -52,7 +57,7 @@ Also, direct your favorite browser to for instance http://localhost:8080/
#### HTTPS
`g++ -O3 -std=c++11 https_examples.cpp -lboost_system -lboost_thread -lssl -lcrypto -o https_examples`
`g++ -O3 -std=c++11 https_examples.cpp -lboost_system -lboost_thread -lboost_coroutine -lboost_context -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