Example/ADDRESS BINDING
Overview
--------
Each network interface on a host usually has a unique IP address. Sockets with wildcard local addresses can receive messages sent to any of the host's addresses on a specific port. For example, if a host has two interfaces with addresses 128.32.0.4 and 10.0.0.78, a socket bound to a wildcard address can accept connections on either. To restrict connections to a specific network, a server binds to the interface address of the desired network.
Example
-------
``C++
#include <memory>
#include <cstdlib>
#include <restbed>
using namespace std;
using namespace restbed;
void get_method_handler( const shared_ptr< Session > session )
{
session->close( OK, "Hello, World!", { { "Content-Length", "13" } } );
}
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "GET", get_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
settings->set_bind_address( "127.0.0.1" );
settings->set_default_header( "Connection", "close" );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -XGET 'http://127.0.0.1:1984/resource'
---
Example/COMPRESSION
Overview
--------
HTTP compression improves transfer speed and reduces bandwidth use by compressing data before it is sent from the server to the client.
Browsers indicate which compression methods they support, and the server responds with a compatible compressed format. If a browser does not support compression, it receives uncompressed data.
Common compression methods include gzip and Deflate, with the complete list of supported schemes maintained by the Internet Assigned Numbers Authority (IANA).
Example
-------
/ Detailed source-code truncated for AI context efficiency. /
Build
-----$ git clone https://github.com/richgel999/miniz.git
$ cd miniz
$ mkdir build; cd build
$ cmake -DBUILD_HEADER_ONLY=ON -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF ..
$ make; sudo make install
> $ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ echo "Hello, World!" > test.data
$ zlib-flate -compress < test.data > test.data.z
$ curl -w'\n' -v -H"Content-Encoding: deflate" -X POST --data-binary @test.data.z 'http://localhost:1984/api/deflate'
---
Example/CUSTOM HTTP METHOD
Overview
--------
A key constraint of HTTP and a core principle of REST is the uniform interface: a small, fixed set of methods applied consistently to all resources.
This standardisation simplifies system design and improves interoperability, but it can also limit flexibility in certain use cases.
Example
-------
#include <memory>
#include <cstdlib>
#include <restbed>
using namespace std;
using namespace restbed;
void nop_method_handler( const shared_ptr< Session > session )
{
session->close( 666 );
}
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "NOP", nop_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
settings->set_default_header( "Connection", "close" );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -X NOP 'http://localhost:1984/resource'
---
Example/CUSTOM STATUS CODE
Overview
--------
The Internet runs on shared conventions known as RFCs (Requests for Comments).
Although RFCs are not laws and violating them carries no legal penalty, doing so can prevent your service from interoperating reliably with other systems on the Internet.
Example
-------
#include <memory>
#include <cstdlib>
#include <restbed>
using namespace std;
using namespace restbed;
void get_method_handler( const shared_ptr< Session > session )
{
session->close( 418 );
}
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "GET", get_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
settings->set_default_header( "Connection", "close" );
settings->set_status_message( 418, "I'm a teapot" );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -X GET 'http://localhost:1984/resource'
---
Example/DIGEST AUTHENTICATION
Overview
--------
Digest access authentication is an HTTP method that allows a web server to verify a userβs credentials (such as username and password) before granting access to protected resources, like online banking data.
Instead of sending credentials in plain form, it applies a cryptographic hash function to the username and password before transmission, improving security.
In contrast, Basic access authentication only uses Base64 encoding, which is easily reversible and does not provide real security unless combined with TLS encryption.
Example
-------
/ Detailed source-code truncated for AI context efficiency. /
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v --digest -XGET 'http://Corvusoft:Glasgow@localhost:1984/resource'
---
Example/ERROR HANDLING
Overview
--------
Error handling is the process of anticipating, detecting, and resolving errors in software and communication systems.
Specialised components, called error handlers, help manage these issues. Effective error handling aims to prevent errors when possible, recover from them without stopping the application, andβif recovery is not possibleβshut down gracefully while recording details in a log for later analysis.
Example
-------
/ Detailed source-code truncated for AI context efficiency. /
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -XGET 'http://localhost:1984/resources/1'
> $ curl -w'\n' -v -XGET 'http://localhost:1984/resources/2'
---
Example/HTTP PERSISTENT CONNECTION
Overview
--------
HTTP persistent connections (also called keep-alive or connection reuse) allow multiple HTTP requestβresponse exchanges to occur over a single TCP connection, instead of creating a new connection for each request. This reduces latency and improves efficiency.
The newer HTTP/2 protocol extends this concept by enabling multiple concurrent requests and responses to be multiplexed over a single connection, further improving performance.
Example
-------
#include <string>
#include <memory>
#include <cstdlib>
#include <restbed>
using namespace std;
using namespace restbed;
void get_intermittent_method_handler( const shared_ptr< Session > session )
{
session->close( OK, "intermittent resource request", { { "Content-Length", "29" }, { "Connection", "close" } } );
}
void get_persistent_method_handler( const shared_ptr< Session > session )
{
session->yield( OK, "persistent resource request", { { "Content-Length", "27" }, { "Connection", "keep-alive" } } );
}
int main( const int, const char )
{
auto persistent = make_shared< Resource >( );
persistent->set_path( "/resources/persistent" );
persistent->set_method_handler( "GET", get_persistent_method_handler );
auto intermittent = make_shared< Resource >( );
intermittent->set_path( "/resources/intermittent" );
intermittent->set_method_handler( "GET", get_intermittent_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
Service service;
service.publish( persistent );
service.publish( intermittent );
service.start( settings );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v 'http://localhost:1984/resources/persistent' 'http://localhost:1984/resources/intermittent'
---
Example/HTTP PIPELINING
Overview
--------
HTTP pipelining allows a client to send multiple HTTP requests over a single TCP connection without waiting for each corresponding response. This can reduce latency by minimising idle time between requests.
However, due to practical issuesβsuch as buggy proxy servers and head-of-line (HOL) blockingβHTTP pipelining has not been enabled by default in modern browsers since around 2017.
Example
-------
/ Detailed source-code truncated for AI context efficiency. /
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ (echo -e "GET /resource/1 HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\nGET /resource/2 HTTP/1.1\r\nConnection: keep-alive\r\nHost: localhost\r\n\r\nGET /resource/3 HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"; sleep 5) | netcat localhost 1984
> $ (echo -e "GET &&%$Β£% /resource/1 HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\nGET /resource/2 HTTP/1.1\r\nConnection: keep-alive\r\nHost: localhost\r\n\r\nGET /resource/3 HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\n"; sleep 5) | netcat localhost 1984
---
Example/HTTP SERVICE
Overview
--------
A web service is a service provided by one electronic device to another over the Web. It uses web technologiesβmost commonly HTTPβto enable machine-to-machine communication.
Although HTTP was originally designed for human-to-machine interaction, web services use it to exchange machine-readable data formats such as XML and JSON.
Example
-------
#include <memory>
#include <cstdlib>
#include <restbed>
using namespace std;
using namespace restbed;
void post_method_handler( const shared_ptr< Session > session )
{
const auto request = session->get_request( );
size_t content_length = request->get_header( "Content-Length", 0 );
session->fetch( content_length, request
{
fprintf( stdout, "%.s\n", ( int ) body.size( ), ( const char ) body.data( ) );
session->close( OK, "Hello, World!", { { "Content-Length", "13" }, { "Connection", "close" } } );
} );
}
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "POST", post_method_handler );
Service service;
service.publish( resource );
service.start( );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -X POST --data 'Hello, Restbed' 'http://localhost/resource'
---
Example/HTTPS SERVICE
Overview
--------
HTTPS (Hypertext Transfer Protocol Secure) is the secure version of HTTP used to transmit data between a web browser and a web server.
It works by encrypting communication using Transport Layer Security (TLS), which replaced the older Secure Sockets Layer (SSL). For this reason, HTTPS is sometimes called HTTP over TLS or HTTP over SSL.
HTTPS provides:
- Confidentiality β Data is encrypted so others cannot read it.
- Integrity β Data cannot be altered during transmission.
- Authentication β Verifies the identity of the website.
Example
-------
#include <memory>
#include <cstdlib>
#include <restbed>
using namespace std;
using namespace restbed;
void get_method_handler( const shared_ptr< Session > session )
{
session->close( OK, "Hello, World!", { { "Content-Length", "13" }, { "Connection", "close" } } );
}
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "GET", get_method_handler );
auto ssl_settings = make_shared< SSLSettings >( );
ssl_settings->set_http_disabled( true );
ssl_settings->set_private_key( Uri( "file:///tmp/server.key" ) );
ssl_settings->set_certificate( Uri( "file:///tmp/server.crt" ) );
ssl_settings->set_temporary_diffie_hellman( Uri( "file:///tmp/dh2048.pem" ) );
auto settings = make_shared< Settings >( );
settings->set_ssl_settings( ssl_settings );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ cd /tmp
> $ openssl genrsa -out server.key 2048
$ openssl req -new -key server.key -out server.csr
$ openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
$ openssl dhparam -out dh2048.pem 2048
> $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -k -v -w'\n' -X GET 'https://localhost/resource'
---
Example/LOGGING
Overview
--------
Logging is the process of recording events or messages in a system, often written to a log file.
A transaction log is a specific type of log that records interactions (transactions) between a system and its users. It can automatically capture details such as:
- Type of transaction
- Content of the transaction
- Time the transaction occurred
Transaction logs are commonly used to monitor activity, troubleshoot issues, and maintain a record of system usage for auditing or recovery purposes.
Example
-------
/ Detailed source-code truncated for AI context efficiency. /
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -XGET 'http://localhost:1984/resource'
---
Example/MULTIPATH RESOURCES
Overview
--------
A web resource is anything that can be identified and accessed on the web. Originally, the term referred to the target of a URL.
Its definition now includes anything identified by a Uniform Resource Identifier (URI) or Internationalised Resource Identifier (IRI).
In the Semantic Web, abstract resources and their properties are described using RDF (Resource Description Framework), which allows machines to understand and process the meaning of resources.
In short, a web resource can be a webpage, a file, a service, or even an abstract concept, as long as it can be identified on the web.
Example
-------
#include <memory>
#include <cstdlib>
#include <restbed>
using namespace std;
using namespace restbed;
void get_method_handler( const shared_ptr< Session > session )
{
session->close( OK, "Hello, World!", { { "Content-Length", "13" } } );
}
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_paths( { "/messages", "/queues/{id: [0-9]*}/messages" } );
resource->set_method_handler( "GET", get_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
settings->set_default_header( "Connection", "close" );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v 'http://localhost:1984/messages'
> $ curl -w'\n' -v 'http://localhost:1984/queues/12/messages'
---
Example/MULTITHREADED SERVICE
Overview
--------
Multithreading in computer architecture is the ability of a CPU (or a single core in a multi-core processor) to execute multiple threads or processes at the same time.
In essence, itβs a way for a processor to do more work simultaneously without needing additional cores.
Example
-------
#include <memory>
#include <thread>
#include <cstdlib>
#include <restbed>
#include <sstream>
using namespace std;
using namespace restbed;
void get_method_handler( const shared_ptr< Session > session )
{
stringstream id;
id << ::this_thread::get_id( );
auto body = "Hello From Thread " + id.str( ) + "\n";
session->close( OK, body, { { "Content-Length", ::to_string( body.length( ) ) } } );
}
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "GET", get_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
settings->set_worker_limit( 4 );
settings->set_default_header( "Connection", "close" );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -X GET 'http://localhost:1984/resource'
---
Example/PAM AUTHENTICATION
Overview
--------
A Pluggable Authentication Module (PAM) is a system that allows multiple low-level authentication methods to be integrated into a single high-level API. This lets applications perform authentication without depending on the specific underlying mechanism.
PAM was first proposed by Sun Microsystems in an Open Software Foundation RFC in 1995 and became the authentication framework for the Common Desktop Environment. As an open-source infrastructure, it appeared in Red Hat Linux 3.0.4 in 1996 through the Linux PAM project. Today, PAM is supported on multiple operating systems, including AIX, DragonFly BSD, FreeBSD, HP-UX, Linux, Mac OS X, NetBSD, and Solaris.
Example
-------
/ Detailed source-code truncated for AI context efficiency. /
Build
-----$ sudo apt-get install libpam0g-dev
$ clang++ -std=c++20 -o example example.cpp -l restbed -l pam
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -XGET 'http://<USERNAME>:<PASSWORD>@localhost:1984/resource'
---
Example/PATH PARAMETERS
Overview
--------
A URI path parameter is a value included within a path segment of a URI, immediately following its name. Path parameters can control how a resource is represented, but since they cannot be modified by standard web forms, they must be constructed separately. Unlike query strings, path parameters are part of the URI path itself and are interpreted in sequence.
Example
-------
#include <string>
#include <memory>
#include <cstdlib>
#include <restbed>
using namespace std;
using namespace restbed;
void get_method_handler( const shared_ptr< Session > session )
{
const auto& request = session->get_request( );
const string body = "Hello, " + request->get_path_parameter( "name" );
session->close( OK, body, { { "Content-Length", ::to_string( body.size( ) ) } } );
}
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/resource/{name: .*}" );
resource->set_method_handler( "GET", get_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
settings->set_default_header( "Connection", "close" );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -XGET 'http://localhost:1984/resource/<YOUR NAME HERE>'
---
Example/RESOURCE AUTHENTICATION
Overview
--------
HTTP Basic authentication (BA) is one of the simplest methods for controlling access to web resources. It does not rely on cookies, session identifiers, or dedicated login pages. Instead, it uses standard fields in the HTTP request header to transmit user credentials, eliminating the need for additional authentication handshakes.
Example
-------
/ Detailed source-code truncated for AI context efficiency. /
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -XGET 'http://ben:1234@localhost:1984/ben'
$ curl -w'\n' -v -XGET 'http://laura:4321@localhost:1984/laura'
---
Example/SERVICE AUTHENTICATION
Overview
--------
HTTP Basic Authentication (BA) is a simple method for enforcing access control to web resources. It does not require cookies, session identifiers, or login pages. Instead, it transmits user credentials through standard fields in the HTTP header, eliminating the need for additional authentication handshakes.
Example
-------
#include <memory>
#include <cstdlib>
#include <ciso646>
#include <functional>
#include <restbed>
using namespace std;
using namespace restbed;
void authentication_handler( const shared_ptr< Session > session,
const function< void ( const shared_ptr< Session > ) >& callback )
{
auto authorisation = session->get_request( )->get_header( "Authorization" );
if ( authorisation not_eq "Basic Q29ydnVzb2Z0OkdsYXNnb3c=" )
{
session->close( UNAUTHORIZED, { { "WWW-Authenticate", "Basic realm=\"restbed\"" } } );
}
else
{
callback( session );
}
}
void get_method_handler( const shared_ptr< Session > session )
{
session->close( OK, "Password Protected Hello, World!", { { "Content-Length", "32" } } );
}
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "GET", get_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
settings->set_default_header( "Connection", "close" );
Service service;
service.publish( resource );
service.set_authentication_handler( authentication_handler );
service.start( settings );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -XGET 'http://Corvusoft:Glasgow@localhost:1984/resource'
---
Example/SERVING HTML
Overview
--------
A web server is either server software, or hardware dedicated to running that software, which delivers content to the World Wide Web. It processes incoming network requestsβprimarily over the HTTP protocol and other related protocolsβand responds by serving web resources such as pages, files, or data.
Example
-------
#include <string>
#include <memory>
#include <cstdlib>
#include <fstream>
#include <restbed>
#include <streambuf>
using namespace std;
using namespace restbed;
void get_method_handler( const shared_ptr< Session > session )
{
const auto request = session->get_request( );
const string filename = request->get_path_parameter( "filename" );
ifstream stream( "./" + filename, ifstream::in );
if ( stream.is_open( ) )
{
const string body = string( istreambuf_iterator< char >( stream ), istreambuf_iterator< char >( ) );
const multimap< string, string > headers
{
{ "Content-Type", "text/html" },
{ "Content-Length", ::to_string( body.length( ) ) }
};
session->close( OK, body, headers );
}
else
{
session->close( NOT_FOUND );
}
}
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/static/{filename: [a-z]*\\.html}" );
resource->set_method_handler( "GET", get_method_handler );
auto settings = make_shared< Settings >( );
settings->set_port( 1984 );
settings->set_default_header( "Connection", "close" );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
}
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ echo "<html>Hello, WORLD</html>" > index.html
> $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ curl -w'\n' -v -X GET 'http://localhost:1984/static/index.html'
---
Example/SYSLOG LOGGING
Overview
--------
In computing, syslog is a standard protocol for message logging. It separates the system components that generate log messages from those that store, analyse, or report on them. Each message includes a facility code (identifying the source software type) and a severity level (indicating the importance of the event).
System designers use syslog for system management, security auditing, debugging, and general informational messages. Many devicesβsuch as printers, routers, and serversβsupport the syslog standard, allowing logs from diverse systems to be centralised in a single repository. Syslog implementations are available for many operating systems.
Example
-------
/ Detailed source-code truncated for AI context efficiency. /
BuildTransfer-Encoding: chunked
-----$ clang++ -std=c++20 -o example example.cpp -l restbedExecution
---------$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib$ ./example> $ curl -w'\n' -v -XGET 'http://localhost:1984/resource'> $ cat var/log/syslog---
Example/TRANSFER ENCODING REQUEST
Overview
--------Chunked transfer encoding is a streaming data transfer mechanism introduced in HTTP/1.1. It allows data to be sent in a series of independent, non-overlapping "chunks" rather than as a single continuous block.
Each chunk is preceded by its size (in bytes), enabling the receiver to process data incrementally without knowing the total content length in advance. The transmission ends when a zero-length chunk is sent. The use of chunked transfer encoding is indicated by the
header.Example
-------
/ Detailed source-code truncated for AI context efficiency. /
Build
-----$ clang++ -std=c++20 -o example example.cpp -l restbed
Execution
---------
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
$ ./example
> $ echo "My really large file..." > bigfile.txt
$ curl -w'\n' -v -X POST --header "Transfer-Encoding: chunked" -d @bigfile.txt 'http://localhost:1984/resources'
---
API
Overview
--------
This document is intended to accurately communicate the Application Programming Interface (API) exposed by the Restbed framework for public consumption.
A description of the framework's software architecture is provided by the Design Overview documentation.
Interpretation
--------------
The key words βMUSTβ, βMUST NOTβ, βREQUIREDβ, βSHALLβ, βSHALL NOTβ, βSHOULDβ, βSHOULD NOTβ, βRECOMMENDEDβ, βMAYβ, and βOPTIONALβ in this document are to be interpreted as described in RFC 2119.
Table of Contents
-----------------
1. Overview
2. Interpretation
3. Bytes
4. Logger
5. Logger::Level
6. Request
7. Response
8. Resource
9. Service
10. Session
11. Settings
12. SSLSettings
13. StatusCode
14. String
15. String::Option
16. URI
17. WebSocket
18. WebSocketMessage
19. WebSocketMessage::OpCode
20. Further Reading
Bytes
typedef std::vector< std::byte > Bytes;
Bytes provides container functionality with the Standard Template Library (STL) vector collection semantics.See std::byte and std::vector for further details.
Logger
Interface detailing the required contract for logger extensions.
No default logger is supplied with the codebase; it is the responsibility of third-party developers to implement the desired behaviour.
#### Methods
- start
- stop
- log
- log_if
- level
#### Logger::start
virtual void start( const std::shared_ptr< const restbed::Settings >& settings ) = 0;
Initialise a logger instance; see also stop.The Settings passed are the same as those given to Service::start.
After this method has returned, the instance MUST be ready to start receiving log and log_if invocations.
##### Parameters
| name | type | default value | direction |
|:-----:|--------------------------------|:-------------:|:---------:|
| value | restbed::Settings | n/a | input |
##### Return Value
n/a
##### Exceptions
Any exceptions raised will result in the service failing to start.
#### Logger::stop
virtual void stop( void ) = 0;
Halt and clean-up logger resources; see also start.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
Exceptions raised will result in a dirty service teardown.
#### Logger::log
virtual void log( const Level level, const char* format, ... ) = 0;
Commit the message specified under the control of a format string, with the specified level of severity, into the log; see also log_if.See the printf family of functions for format directives.
The format string is composed of zero or more directives: ordinary characters (not %), which are copied unchanged to the output stream; and conversion specifications, each of which results in fetching zero or more subsequent arguments. Each conversion specification is >introduced by the % character.
##### Parameters
| name | type | default value | direction |
|:------:|-----------------------------------------------------------------------------|:-------------:|:---------:|
| level | restbed::Logger::Level | n/a | input |
| format | char\* | n/a | input |
| ... | variadic argument list | n/a | input |
##### Return Value
n/a
##### Exceptions
Any exceptions raised will result in the service ignoring the fault and printing directly to Standard Error (stderr).
#### Logger::log_if
virtual void log_if( bool expression, const Level level, const char* format, ... ) = 0;
Commit the message specified under the control of a format string, with the specified level of severity, into the log, under the condition that the expression is equal to true; see also log.##### Parameters
| name | type | default value | direction |
|:-----------:|-----------------------------------------------------------------------------|:-------------:|:---------:|
| expression | bool | n/a | input |
| level | restbed::Logger::Level | n/a | input |
| format | char\* | n/a | input |
| ... | variadic argument list | n/a | input |
##### Return Value
n/a
##### Exceptions
Any exceptions raised will result in the service ignoring the fault and printing directly to Standard Error (stderr).
#### Logger::Level
class Logger
{
enum Level : int
{
INFO = 0000,
DEBUG = 1000,
FATAL = 2000,
ERROR = 3000,
WARNING = 4000,
SECURITY = 5000
};
}
Enumeration is used in conjunction with the Logger interface to detail the level of severity towards a particular log entry.Request
Represents an HTTP request with additional helper methods for manipulating data and improving code readability.
#### Methods
- constructor
- destructor
- has_header
- has_path_parameter
- has_query_parameter
- get_port
- get_version
- get_body
- get_response
- get_host
- get_path
- get_method
- get_protocol
- get_header
- get_headers
- get_query_parameter
- get_query_parameters
- get_path_parameter
- get_path_parameters
- set_body
- set_port
- set_version
- set_path
- set_host
- set_method
- set_protocol
- add_header
- set_header
- set_headers
- set_query_parameter
- set_query_parameters
#### Request::constructor
Request( void );
Request( const Uri& value );
Initialises a new class instance; if a Uri is supplied, it will be used to override the default class property values; see also destructor.##### Parameters
| name | type | default value | direction |
|:-----:|-------------|:-------------:|:---------:|
| value | Uri | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::destructor
virtual ~Request( void );
Clean-up class instance; see also constructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
No exceptions allowed specification: noexcept.
#### Request::has_header
bool has_header( const std::string& name ) const;
Case-insensitive check to confirm if the request contains a header with the supplied name.##### Parameters
| name | type | default value | direction |
|:----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
##### Return Value
Boolean true if the request holds a header with a matching name, else false.
##### Exceptions
No exceptions allowed specification: noexcept.
#### Request::has_path_parameter
bool has_path_parameter( const std::string& name ) const;
Case-insensitive check to confirm if the request contains a path parameter with the supplied name.##### Parameters
| name | type | default value | direction |
|:----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
##### Return Value
Boolean true if the request holds a path parameter with a matching name, else false.
##### Exceptions
No exceptions allowed specification: noexcept.
#### Request::has_query_parameter
bool has_query_parameter( const std::string& name ) const;
Case-insensitive check to confirm if the request contains a query parameter with the supplied name.##### Parameters
| name | type | default value | direction |
|:----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
##### Return Value
Boolean true if the request holds a query parameter with a matching name, else false.
##### Exceptions
No exceptions allowed specification: noexcept.
#### Request::get_port
uint16_t get_port( void ) const;
Retrieves the network port number of the server endpoint; see also set_port.##### Parameters
n/a
##### Return Value
uint16_t representing the network port number.
##### Exceptions
n/a
#### Request::get_version
double get_version( void ) const;
Retrieves the HTTP version number; see also set_version.##### Parameters
n/a
##### Return Value
double representing the HTTP version.
##### Exceptions
n/a
#### Request::get_body
Bytes get_body( void ) const;
1) Retrieves the contents of the request body as Bytes; see also set_body.##### Parameters
n/a
##### Return Value
Bytes representing the request body.
##### Exceptions
n/a
#### Request::get_response
const std::shared_ptr< const Response > get_response( void ) const;
Retrieves the associated HTTP response for this request, if any.##### Parameters
n/a
##### Return Value
std::shared_ptr representing the response, else nullptr.
##### Exceptions
n/a
#### Request::get_host
std::string get_host( void ) const;
Retrieves the host for this request.##### Parameters
n/a
##### Return Value
std::string representing the host.
##### Exceptions
n/a
#### Request::get_path
std::string get_path( void ) const;
Retrieves the path for this request.##### Parameters
n/a
##### Return Value
std::string representing the path.
##### Exceptions
n/a
#### Request::get_method
std::string get_method( void ) const;
Retrieves the HTTP method for this request.##### Parameters
n/a
##### Return Value
std::string representing the HTTP method.
##### Exceptions
n/a
#### Request::get_protocol
std::string get_protocol( void ) const;
Retrieves the protocol for this request.##### Parameters
n/a
##### Return Value
std::string representing the protocol.
##### Exceptions
n/a
#### Request::get_header
template< typename Type, typename std::enable_if< std::is_arithmetic< Type >::value, Type >::type = 0 >
Type get_header( const std::string& name, const Type default_value ) const
std::string get_header( const std::string& name, const std::string& default_value ) const;
1) Retrieve the first header with a matching name, parsing to an arithmetic value. If not found, return default_value.2) Retrieve the first header with a matching name as a std::string. If not found, return default_value.
##### Parameters
| name | type | default value | direction |
|:-------------:|-----------------------------------------------------------------------------------|:-------------:|:---------:|
| header name | std::string | n/a | input |
| default_value | std::string | n/a | input |
##### Return Value
std::string or arithmetic value representing the header.
##### Exceptions
n/a
#### Request::get_headers
std::multimap< std::string, std::string > get_headers( const std::string& name = "" ) const;
Retrieves all headers as a std::multimap. If a name is supplied, only matching headers will be returned.##### Parameters
| name | type | default value | direction |
|:------------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| header name | std::string | n/a | input |
##### Return Value
std::multimap representing a collection of headers.
##### Exceptions
n/a
#### Request::get_query_parameter
template< typename Type, typename std::enable_if< std::is_arithmetic< Type >::value, Type >::type = 0 >
Type get_query_parameter( const std::string& name, const Type default_value ) const
std::string get_query_parameter( const std::string& name, const std::string& default_value ) const;
1) Retrieve the first query parameter with a matching name, parsing to an arithmetic value. If not found, return default_value.2) Retrieve the first query parameter with a matching name as a std::string. If not found, return default_value.
##### Parameters
| name | type | default value | direction |
|:--------------:|-----------------------------------------------------------------------------------|:-------------:|:---------:|
| parameter name | std::string or arithmetic | n/a | input |
| default_value | std::string or arithmetic | n/a | input |
##### Return Value
std::string or an arithmetic value representing the query parameter.
##### Exceptions
n/a
#### Request::get_query_parameters
std::multimap< std::string, std::string > get_query_parameters( const std::string& name = "", const String::Option option = String::CASE_INSENSITIVE ) const;
Retrieves all query parameters as a std::multimap. If a name is supplied, only matching parameters will be returned.##### Parameters
| name | type | default value | direction |
|:--------------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| parameter name | String::Option | n/a | input |
| option | String::Option | n/a | input |
##### Return Value
std::multimap representing a collection of parameters.
##### Exceptions
n/a
#### Request::get_path_parameter
template< typename Type, typename std::enable_if< std::is_arithmetic< Type >::value, Type >::type = 0 >
Type get_path_parameter( const std::string& name, const Type default_value ) const
std::string get_path_parameter( const std::string& name, const std::string& default_value ) const;
1) Retrieve the first parameter with a matching name, parsing to an arithmetic value. If not found, return default_value.2) Retrieve the first parameter with a matching name as a std::string. If not found, return default_value.
##### Parameters
| name | type | default value | direction |
|:--------------:|-----------------------------------------------------------------------------------|:-------------:|:---------:|
| parameter name | String::Option | n/a | input |
| default_value | std::string or arithmetic | n/a | input |
##### Return Value
std::string or arithmetic value representing the path parameter.
##### Exceptions
n/a
#### Request::get_path_parameters
std::multimap< std::string, std::string > get_path_parameters( const std::string& name = "" ) const;
Retrieves all query parameters as a std::multimap. If a name is supplied, only matching parameters will be returned.##### Parameters
| name | type | default value | direction |
|:--------------:|-----------------------------------------------------------------------------------|:-------------:|:---------:|
| parameter name | String::Option | n/a | input |
##### Return Value
std::multimap representing a collection of parameters.
##### Exceptions
n/a
#### Request::set_body
void set_body( const Bytes& value );
void set_body( const std::string& value );
Replace request body; see also get_body.##### Parameters
| name | type | default value | direction |
|:-----:|--------------------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string or Bytes | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::set_port
void set_port( const uint16_t value );
Replace request network port; see also get_port.##### Parameters
| name | type | default value | direction |
|:-----:|-----------------------------------------------------------------|:-------------:|:---------:|
| value | std::uint16_t | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::set_version
void set_version( const double value );
Replace request version; see also get_version.##### Parameters
| name | type | default value | direction |
|:-----:|-----------------------------------------------------------------------------------|:-------------:|:---------:|
| value | double | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::set_path
void set_path( const std::string& value );
Replace request path; see also get_path.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::set_host
void set_host( const std::string& value );
Replace request host; see also get_host.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::set_method
void set_method( const std::string& value );
Replace request method; see also get_method.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::set_protocol
void set_protocol( const std::string& value );
Replace request protocol; see also get_protocol.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::add_header
void add_header( const std::string& name, const std::string& value );
Add an HTTP header to the request; existing headers that share the same name will not be altered.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::set_header
void set_header( const std::string& name, const std::string& value );
Set an HTTP header; existing headers that share the same name will be erased.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::set_headers
void set_headers( const std::multimap< std::string, std::string >& values );
Set HTTP headers; existing headers will be erased.##### Parameters
| name | type | default value | direction |
|:------:|----------------------------------------------------------------------|:-------------:|:---------:|
| values | std::multimap | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::set_query_parameter
void set_query_parameter( const std::string& name, const std::string& value );
Set HTTP query parameter; existing parameters that share the same name will be erased.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Request::set_query_parameters
void set_query_parameters( const std::multimap< std::string, std::string >& values );
Set HTTP query parameters; existing parameters will be erased.##### Parameters
| name | type | default value | direction |
|:------:|----------------------------------------------------------------------|:-------------:|:---------:|
| values | std::multimap | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
Response
Represents an HTTP response with additional helper methods for manipulating data and improving code readability.
#### Methods
- constructor
- destructor
- has_header
- get_body
- get_version
- get_status_code
- get_protocol
- get_status_message
- get_header
- get_headers
- set_body
- set_version
- set_status_code
- set_protocol
- set_status_message
- add_header
- set_header
- set_headers
#### Response::constructor
Response( void );
Initialises a new class instance; see also the destructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### Response::destructor
virtual ~Response( void );
Clean-up class instance; see also the constructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
No exceptions allowed specification: noexcept.
#### Response::has_header
bool has_header( const std::string& name ) const;
Case-insensitive check to confirm if the response contains a header with the supplied name.##### Parameters
| name | type | default value | direction |
|:----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
##### Return Value
Boolean true if the response holds a header with a matching name, else false.
##### Exceptions
No exceptions allowed specification: noexcept.
#### Response::get_body
Bytes get_body( void ) const;
1) Retrieves the contents of the response body as Bytes; see also set_body.##### Parameters
n/a
##### Return Value
Bytes representing the response body.
##### Exceptions
n/a
#### Response::get_version
double get_version( void ) const;
Retrieves the HTTP version number; see also set_version.##### Parameters
n/a
##### Return Value
double representing the HTTP version.
##### Exceptions
n/a
#### Response::get_status_code
int get_status_code( void ) const;
Retrieves the HTTP status code; see also set_status_code.##### Parameters
n/a
##### Return Value
Integer representing the HTTP status code.
##### Exceptions
n/a
#### Response::get_protocol
std::string get_protocol( void ) const;
Retrieve the protocol.##### Parameters
n/a
##### Return Value
std::string representing the protocol.
##### Exceptions
n/a
#### Response::get_status_message
std::string get_status_message( void ) const;
Retrieves the HTTP status message; see also set_status_message.##### Parameters
n/a
##### Return Value
std::string representing the HTTP status message.
##### Exceptions
n/a
#### Response::get_header
template< typename Type, typename std::enable_if< std::is_arithmetic< Type >::value, Type >::type = 0 >
Type get_header( const std::string& name, const Type default_value ) const
std::string get_header( const std::string& name, const std::string& default_value ) const;
1) Retrieve the first header with a matching name, parsing to an arithmetic value. If not found, return default_value.2) Retrieve the first header with a matching name as a std::string. If not found, return default_value.
##### Parameters
| name | type | default value | direction |
|:-------------:|-----------------------------------------------------------------------------------|:-------------:|:---------:|
| header name | std::string or arithmetic | n/a | input |
| default_value | std::string or arithmetic | n/a | input |
##### Return Value
std::string or arithmetic value representing the header.
##### Exceptions
n/a
#### Response::get_headers
std::multimap< std::string, std::string > get_headers( const std::string& name = "" ) const;
Retrieves all headers as a std::multimap. If a name is supplied, only matching headers will be returned.##### Parameters
| name | type | default value | direction |
|:-------------:|-----------------------------------------------------------------------------------|:-------------:|:---------:|
| header name | std::string or arithmetic | n/a | input |
##### Return Value
std::multimap representing a collection of headers.
##### Exceptions
n/a
#### Response::set_body
void set_body( const Bytes& value );
void set_body( const std::string& value );
Replace response body; see also get_body.##### Parameters
| name | type | default value | direction |
|:-----:|--------------------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string or Bytes | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Response::set_version
void set_version( const double value );
Replace response version; see also get_version.##### Parameters
| name | type | default value | direction |
|:-----:|-----------------------------------------------------------------------------------|:-------------:|:---------:|
| value | double | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Response::set_status_code
void set_status_code( const int value );
Replace response status code; see also get_status_code.##### Parameters
| name | type | default value | direction |
|:-----:|----------------------------------------------------------------------|:-------------:|:---------:|
| value | int | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Response::set_protocol
void set_protocol( const std::string& value );
Replace response protocol; see also get_protocol.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Response::set_status_message
void set_status_message( const std::string& value );
Replace response status message; see also get_status_message.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Response::add_header
void add_header( const std::string& name, const std::string& value );
Add an HTTP header to the response; existing headers that share the same name will not be altered.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Response::set_header
void set_header( const std::string& name, const std::string& value );
Set an HTTP header; existing headers that share the same name will be erased; see also get_header.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Response::set_headers
void set_headers( const std::multimap< std::string, std::string >& values );
Set HTTP headers, existing headers will be erased; see also get_headers.##### Parameters
| name | type | default value | direction |
|:------:|----------------------------------------------------------------------|:-------------:|:---------:|
| values | std::multimap | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
Resource
Resource represents a network communication endpoint. This is the primary data structure used throughout to represent RESTful resources. All resource-specific filtration, request processing, and authentication must be placed on this entity.
#### Methods
- constructor
- destructor
- set_path
- set_paths
- set_default_header
- set_default_headers
- set_error_handler
- set_authentication_handler
- set_method_handler
#### Resource::constructor
Resource( void );
Initialises a new class instance; see also destructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### Resource::destructor
virtual ~Resource( void );
Clean-up class instance; see also constructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
No exceptions allowed specification: noexcept.
#### Resource::set_path
void set_path( const std::string& value );
Set the path by which this resource should be accessible. Settings::set_root will be prepended to this value.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Resource::set_paths
void set_paths( const std::set< std::string >& values );
Set the paths with which this resource should be accessible. Settings::set_root will be prepended to all values.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| values | std::set | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Resource::set_default_header
void set_default_header( const std::string& name, const std::string& value );
Set a default header that should be sent on every HTTP response, overriding any existing value with the same name.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Resource::set_default_headers
void set_default_headers( const std::multimap< std::string, std::string >& values );
Set default headers that should be sent on every HTTP response, overriding any existing values.##### Parameters
| name | type | default value | direction |
|:----------:|----------------------------------------------------------------------|:-------------:|:---------:|
| values | std::multimap | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Resource::set_error_handler
void set_error_handler( const std::function< void ( const int, const std::exception&, const std::shared_ptr< Session > ) >& value );
Set error handler. During processing, if a failure occurs, this method will be invoked for reporting and HTTP response error handling.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Resource::set_authentication_handler
void set_authentication_handler( const std::function< void ( const std::shared_ptr< Session >, const std::function< void ( const std::shared_ptr< Session > ) >& ) >& value );
Set the authentication handler; this method will be invoked after the service authentication handler.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Resource::set_method_handler
void set_method_handler( const std::string& method, const std::function< void ( const std::shared_ptr< Session > ) >& callback );
Set method handler.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| method | std::string | n/a | input |
| callback | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
Service
The service is responsible for managing the publicly available RESTful resources, HTTP compliance, scheduling of the socket data and ensuring incoming requests are processed in a timely fashion.
#### Methods
- constructor
- destructor
- is_up
- is_down
- stop
- start
- publish
- suppress
- get_uptime
- get_http_uri
- get_https_uri
- get_io_context
- set_logger
- set_ready_handler
- set_not_found_handler
- set_method_not_allowed_handler
- set_method_not_implemented_handler
- set_error_handler
- set_authentication_handler
#### Service::constructor
Service( void );
Initialises a new class instance; see also destructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### Service::destructor
virtual ~Service( void );
Clean-up class instance; see also constructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
No exceptions allowed specification: noexcept.
#### Service::is_up
bool is_up( void ) const;
Return a boolean value indicating if the service is currently online and serving incoming requests.##### Parameters
n/a
##### Return Value
Boolean true if the service is online, else false.
##### Exceptions
n/a
#### Service::is_down
bool is_down( void ) const;
Return a boolean value indicating if the service is currently offline and serving incoming requests.##### Parameters
n/a
##### Return Value
Boolean true if the service is offline, else false.
##### Exceptions
n/a
#### Service::stop
void stop( void ) const;
Shut the service down, closing open sessions and terminating threads that may be running.##### Parameters
n/a
##### Return Value
Boolean true if the service is offline, else false.
##### Exceptions
n/a
#### Service::start
void start( const std::shared_ptr< const Settings >& settings = nullptr );
Start the service with the supplied settings; otherwise, default values will be set.##### Parameters
| name | type | default value | direction |
|:----------:|-----------------------------------------------------------------------|:-------------:|:---------:|
| settings | std::shared_ptr | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Service::publish
void publish( const std::shared_ptr< const Resource >& resource );
Publish a RESTful resource for public consumption; see also Resource.##### Parameters
| name | type | default value | direction |
|:----------:|-----------------------------------------------------------------------|:-------------:|:---------:|
| resource | std::shared_ptr | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Service::suppress
void suppress( const std::shared_ptr< const Resource >& resource );
Suppress an already published RESTful resource; see also Resource.##### Parameters
| name | type | default value | direction |
|:----------:|-----------------------------------------------------------------------|:-------------:|:---------:|
| resource | std::shared_ptr | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Service::get_uptime
const std::chrono::seconds get_uptime( void ) const;
Return the number of seconds that have passed since the service was brought online.##### Parameters
n/a
##### Return Value
Number of seconds since calling start.
##### Exceptions
n/a
#### Service::get_http_uri
const std::shared_ptr< const Uri > get_http_uri( void ) const;
Return a URI representing the HTTP endpoint; see also URI.##### Parameters
n/a
##### Return Value
URI representing the HTTP endpoint.
##### Exceptions
n/a
#### Service::get_https_uri
const std::shared_ptr< const Uri > get_https_uri( void ) const;
Return a URI representing the HTTPS endpoint; see also URI.##### Parameters
n/a
##### Return Value
URI representing HTTPS endpoint.
##### Exceptions
n/a
#### Service::get_io_context
std::shared_ptr< asio::io_context > get_io_context( void ) const;
Return the ASIO input/output context.##### Parameters
n/a
##### Return Value
ASIO input/output runtime context.
##### Exceptions
n/a
#### Service::set_logger
void set_logger( const std::shared_ptr< Logger >& value );
Set the logger instance to be used; see also Logger.##### Parameters
| name | type | default value | direction |
|:----------:|-----------------------------------------------------------------------|:-------------:|:---------:|
| value | std::shared_ptr | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Service::set_ready_handler
void set_ready_handler( const std::function< void ( Service& ) >& value );
Set a handler to be invoked once the service is up and ready to serve incoming HTTP requests.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Service::set_not_found_handler
void set_not_found_handler( const std::function< void ( const std::shared_ptr< Session > ) >& value );
If an incoming HTTP request cannot be matched to a known resource, its session will be handed over to the resource not found handler.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Service::set_method_not_allowed_handler
void set_method_not_allowed_handler( const std::function< void ( const std::shared_ptr< Session > ) >& value );
If an incoming HTTP request cannot be matched to a known resource method handler, its session will be routed over to the method not found handler.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Service::set_method_not_implemented_handler
void set_method_not_implemented_handler( const std::function< void ( const std::shared_ptr< Session > ) >& value );
If none of the service resources have a handler for an incoming HTTP request method, its session shall be routed to the method-not-implemented handler.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Service::set_error_handler
void set_error_handler( const std::function< void ( const int, const std::exception&, const std::shared_ptr< Session > ) >& value );
If an error occurs during processing and no resource-specific error handler can be obtained, the global service error handler will be invoked if set.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Service::set_authentication_handler
void set_authentication_handler( const std::function< void ( const std::shared_ptr< Session >, const std::function< void ( const std::shared_ptr< Session > ) >& ) >& value );
Set a service-wide authentication handler before invoking resource-specific authentication handlers.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
Session
Represents a conversation between a client and the service. Internally, this class holds the network state and exposes public functionality to interact with the service event-loop for asynchronous data acquisition and/or sleep states.
#### Methods
- constructor
- destructor
- is_open
- is_closed
- close
- yield
- fetch
- upgrade
- sleep_for
- get_origin
- get_destination
- get_request
- get_resource
- get_headers
- add_header
- set_header
- set_headers
#### Session::constructor
Session( void );
Initialises a new class instance; see also destructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### Session::destructor
virtual ~Session( void );
Clean-up class instance; see also constructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
No exceptions allowed specification: noexcept.
#### Session::is_open
bool is_open( void ) const;
Return the status of the underlying Session socket.##### Parameters
n/a
##### Return Value
Boolean true if the session is active.
##### Exceptions
n/a
#### Session::is_closed
bool is_closed( void ) const;
Return the status of the underlying Session socket.##### Parameters
n/a
##### Return Value
Boolean true if the session is inactive.
##### Exceptions
n/a
#### Session::close
void close( const Bytes& body );
void close( const Response& response );
void close( const std::string& body = "" );
void close( const int status, const Bytes& body );
void close( const int status, const std::string& body = "" );
void close( const int status, const std::multimap< std::string, std::string >& headers );
void close( const int status, const std::string& body, const std::multimap< std::string, std::string >& headers );
void close( const int status, const Bytes& body, const std::multimap< std::string, std::string >& headers );
Close an active session, returning a tailored HTTP response based on the supplied parameters.##### Parameters
| name | type | default value | direction |
|:----------:|--------------------------------------------------------------------------------------------|:-------------:|:---------:|
| status | int | n/a | input |
| body | std::string or Bytes | n/a | input |
| headers | std::multimap | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Session::yield
void yield( const Bytes& data, const std::function< void ( const std::shared_ptr< Session > ) >& callback = nullptr );
void yield( const std::string& data, const std::function< void ( const std::shared_ptr< Session > ) >& callback = nullptr );
void yield( const Response& response, const std::function< void ( const std::shared_ptr< Session > ) >& callback = nullptr );
void yield( const int status, const std::string& body, const std::function< void ( const std::shared_ptr< Session > ) >& callback = nullptr );
void yield( const int status, const Bytes& body = { }, const std::function< void ( const std::shared_ptr< Session > ) >& callback = nullptr );
void yield( const int status, const std::multimap< std::string, std::string >& headers, const std::function< void ( const std::shared_ptr< Session > ) >& callback = nullptr );
void yield( const int status, const Bytes& body, const std::multimap< std::string, std::string >& headers, const std::function< void ( const std::shared_ptr< Session > ) >& callback = nullptr );
void yield( const int status, const std::string& body, const std::multimap< std::string, std::string >& headers, const std::function< void ( const std::shared_ptr< Session > ) >& callback = nullptr );
Return a tailored HTTP response based on the supplied parameters without closing the underlying socket connection; On completion, invoke the callback.##### Parameters
| name | type | default value | direction |
|:----------:|--------------------------------------------------------------------------------------------|:-------------:|:---------:|
| status | int | n/a | input |
| body | std::string or Bytes | n/a | input |
| headers | std::multimap | n/a | input |
| callback | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Session::fetch
void fetch( const std::size_t length, const std::function< void ( const std::shared_ptr< Session >, const Bytes& ) >& callback );
void fetch( const std::string& delimiter, const std::function< void ( const std::shared_ptr< Session >, const Bytes& ) >& callback );
1) Fetch length bytes from the underlying socket connection.2) Fetch bytes from the underlying socket connection until encountering the delimiter.
##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| length | std::size_t | n/a | input |
| delimiter | std::string | n/a | input |
| callback | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Session::upgrade
void upgrade( const int status, const std::function< void ( const std::shared_ptr< WebSocket > ) >& callback );
void upgrade( const int status, const Bytes& body, const std::function< void ( const std::shared_ptr< WebSocket > ) >& callback );
void upgrade( const int status, const std::string& body, const std::function< void ( const std::shared_ptr< WebSocket > ) >& callback );
void upgrade( const int status, const std::multimap< std::string, std::string >& headers, const std::function< void ( const std::shared_ptr< WebSocket > ) >& callback );
void upgrade( const int status, const Bytes& body, const std::multimap< std::string, std::string >& headers, const std::function< void ( const std::shared_ptr< WebSocket > ) >& callback );
void upgrade( const int status, const std::string& body, const std::multimap< std::string, std::string >& headers, const std::function< void ( const std::shared_ptr< WebSocket > ) >& callback );
Return a tailored HTTP response based on the supplied parameters and upgrade to the WebSocket protocol; On completion, invoke the callback.##### Parameters
| name | type | default value | direction |
|:----------:|-----------------------------------------------------------------------------------------------|:-------------:|:---------:|
| status | int | n/a | input |
| body | std::string or Bytes | n/a | input |
| headers | std::multimap | n/a | input |
| callback | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Session::sleep_for
void sleep_for( const std::chrono::milliseconds& delay, const std::function< void ( const std::shared_ptr< Session > ) >& callback );
Place a task on the Service event loop to be run in delay milliseconds.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| delay | std::chrono::milliseconds | n/a | input |
| callback | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Session::get_origin
const std::string get_origin( void ) const;
Return a string representing an Internet Protocol address and port number identifying the source of the current HTTP request.##### Parameters
n/a
##### Return Value
std::string representing the source network endpoint.
##### Exceptions
n/a
#### Session::get_destination
const std::string get_destination( void ) const;
Return a string representing an Internet Protocol address and port number identifying the original destination of the current HTTP request.##### Parameters
n/a
##### Return Value
std::string representing a destination network endpoint.
##### Exceptions
n/a
#### Session::get_request
const std::shared_ptr< const Request > get_request( void ) const;
Return the currently active HTTP request.##### Parameters
n/a
##### Return Value
std::shared_ptr representing an HTTP request.
##### Exceptions
n/a
#### Session::get_resource
const std::shared_ptr< const Resource > get_resource( void ) const;
Return the currently active RESTful resource.##### Parameters
n/a
##### Return Value
std::shared_ptr representing an HTTP request.
##### Exceptions
n/a
#### Session::get_headers
const std::multimap< std::string, std::string >& get_headers( void ) const;
Return the default session header that must be present on each HTTP response.##### Parameters
n/a
##### Return Value
std::multimap representing a collection of HTTP headers.
##### Exceptions
n/a
#### Session::add_header
void add_header( const std::string& name, const std::string& value );
Add a default HTTP header to the session; existing headers that share the same name will not be altered.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Session::set_header
void set_header( const std::string& name, const std::string& value );
Set a default HTTP header for the session; existing headers that share the same name will be erased.##### Parameters
| name | type | default value | direction |
|:-----:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Session::set_headers
void set_headers( const std::multimap< std::string, std::string >& values );
Set default HTTP headers for the session; existing headers will be erased; see also get_headers.##### Parameters
| name | type | default value | direction |
|:------:|----------------------------------------------------------------------|:-------------:|:---------:|
| values | std::multimap | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
Settings
Represents service configuration.
#### Methods
- constructor
- destructor
- get_port
- get_root
- get_ipc_path
- get_reuse_address
- get_worker_limit
- get_connection_limit
- get_bind_address
- get_case_insensitive_uris
- get_connection_timeout
- get_status_message
- get_status_messages
- get_property
- get_properties
- get_ssl_settings
- get_default_headers
- set_port
- set_root
- set_ipc_path
- set_reuse_address
- set_worker_limit
- set_connection_limit
- set_bind_address
- set_case_insensitive_uris
- set_connection_timeout
- set_status_message
- set_status_messages
- set_property
- set_properties
- set_ssl_settings
- set_default_header
- set_default_headers
#### Settings::constructor
Settings( void );
Initialises a new class instance; see also destructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::destructor
virtual ~Settings( void );
Clean-up class instance; see also constructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
No exceptions allowed specification: noexcept.
#### Settings::get_port
uint16_t get_port( void ) const;
Retrieves the network port number on which the service will listen.##### Parameters
n/a
##### Return Value
uint16_t representing the network port number.
##### Exceptions
n/a
#### Settings::get_root
std::string get_root( void ) const;
Retrieves the base path for all resource paths.##### Parameters
n/a
##### Return Value
std::string representing the filesystem path.
##### Exceptions
n/a
#### Settings::get_ipc_path
std::string get_ipc_path( void ) const;
Retrieves the path for IPC sockets.##### Parameters
n/a
##### Return Value
std::string representing the filesystem path.
##### Exceptions
n/a
#### Settings::get_reuse_address
bool get_reuse_address( void ) const;
Determine if socket option reuse address should be used.##### Parameters
n/a
##### Return Value
Boolean indicating reuse address socket option.
##### Exceptions
n/a
#### Settings::get_worker_limit
unsigned int get_worker_limit( void ) const;
Retrieves the number of workers (threads) used for processing incoming requests.##### Parameters
n/a
##### Return Value
unsigned integer detailing the number of service workers.
##### Exceptions
n/a
#### Settings::get_connection_limit
unsigned int get_connection_limit( void ) const;
Retrieves the number of allowed pending socket connections.##### Parameters
n/a
##### Return Value
unsigned integer detailing the number of allowed pending socket connections.
##### Exceptions
n/a
#### Settings::get_bind_address
std::string get_bind_address( void ) const;
Retrieves the local network interface card address to attach the service.##### Parameters
n/a
##### Return Value
std::string detailing the service bind address.
##### Exceptions
n/a
#### Settings::get_case_insensitive_uris
bool get_case_insensitive_uris( void ) const;
Retrieves a boolean value indicating if the service should use case-insensitive URIs.##### Parameters
n/a
##### Return Value
Boolean indicating case-insensitive URI processing.
##### Exceptions
n/a
#### Settings::get_connection_timeout
std::chrono::milliseconds get_connection_timeout( void ) const;
Retrieves the number of milliseconds before an inactive socket is forcefully closed.##### Parameters
n/a
##### Return Value
Milliseconds detailing when to close an inactive socket.
##### Exceptions
n/a
#### Settings::get_status_message
std::string get_status_message( const int code ) const;
Retrieves the HTTP status message associated with the supplied status code.##### Parameters
| name | type | default value | direction |
|:----------:|--------------------------------------------------------|:-------------:|:---------:|
| code | int | n/a | input |
##### Return Value
HTTP status message as a std::string.
##### Exceptions
n/a
#### Settings::get_status_messages
std::map< int, std::string > get_status_messages( void ) const;
Retrieves the HTTP status messages.##### Parameters
n/a
##### Return Value
std::map containing the known HTTP status messages.
##### Exceptions
n/a
#### Settings::get_property
std::string get_property( const std::string& name ) const;
Retrieves a string property with the supplied name if it exists; otherwise, an empty string will be returned.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
##### Return Value
std::string property value.
##### Exceptions
n/a
#### Settings::get_properties
std::map< std::string, std::string > get_properties( void ) const;
Retrieves all setting properties.##### Parameters
n/a
##### Return Value
std::map containing the known settings.
##### Exceptions
n/a
#### Settings::get_ssl_settings
std::shared_ptr< const SSLSettings > get_ssl_settings( void ) const;
Retrieves Secure Socket Layer settings.##### Parameters
n/a
##### Return Value
SSLSettings detailing SSL configuration.
##### Exceptions
n/a
#### Settings::get_default_headers
std::multimap< std::string, std::string > get_default_headers( void ) const;
Retrieves all known default response headers.##### Parameters
n/a
##### Return Value
std::multimap containing all known default response headers.
##### Exceptions
n/a
#### Settings::set_port
void set_port( const uint16_t value );
Set the network port on which the service should listen for incoming HTTP requests.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | uint16_t | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_root
void set_root( const std::string& value );
Set the base resource path; this value is prepended to all resource paths.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_ipc_path
std::string set_ipc_path( const std::string& value ) const;
Set the path for IPC sockets.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_reuse_address
void set_reuse_address( const bool value ) const;
Set reuse address socket option.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------|:-------------:|:---------:|
| value | Boolean | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_worker_limit
void set_worker_limit( const unsigned int value );
Set the number of threads available for incoming HTTP request processing.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | unsigned integer | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_connection_limit
void set_connection_limit( const unsigned int value );
Set the number of allowed pending connections.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | unsigned integer | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_bind_address
void set_bind_address( const std::string& value );
Set the network interface card address with which the service should attach itself.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_case_insensitive_uris
void set_case_insensitive_uris( const bool value );
Set true for case-insensitive URI handling.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | bool | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_connection_timeout
void set_connection_timeout( const std::chrono::seconds& value );
void set_connection_timeout( const std::chrono::milliseconds& value );
Set the duration before forcefully closing inactive socket connections.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | seconds | n/a | input |
| value | milliseconds | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_status_message
void set_status_message( const int code, const std::string& message );
Associate an HTTP status message with an HTTP status code.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| code | integer | n/a | input |
| message | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_status_messages
void set_status_messages( const std::map< int, std::string >& values );
Set HTTP status message/status code mappings.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| values | std::map | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_property
void set_property( const std::string& name, const std::string& value );
Set a string property value with the associated name.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_properties
void set_properties( const std::map< std::string, std::string >& values );
Set multiple property values.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| values | std::map | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_ssl_settings
void set_ssl_settings( const std::shared_ptr< const SSLSettings >& value );
Set Secure Socket Layer configuration.##### Parameters
| name | type | default value | direction |
|:----------:|--------------------------------------|:-------------:|:---------:|
| value | SSLSettings | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_default_header
void set_default_header( const std::string& name, const std::string& value );
Set a default header value that must be returned for each HTTP request response.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::string | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### Settings::set_default_headers
void set_default_headers( const std::multimap< std::string, std::string >& values );
Set multiple default header values that must be returned for each HTTP request response.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| name | std::multimap| n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
SSLSettings
Represents Secure Socket Layer configuration.
#### Methods
- constructor
- destructor
- has_disabled_http
- has_enabled_sslv2
- has_enabled_sslv3
- has_enabled_tlsv1
- has_enabled_tlsv11
- has_enabled_tlsv12
- has_enabled_compression
- has_enabled_default_workarounds
- has_enabled_single_diffie_hellman_use
- get_port
- get_bind_address
- get_certificate
- get_passphrase
- get_private_key
- get_private_rsa_key
- get_certificate_chain
- get_temporary_diffie_hellman
- get_certificate_authority_pool
- set_port
- set_bind_address
- set_http_disabled
- set_sslv2_enabled
- set_sslv3_enabled
- set_tlsv1_enabled
- set_tlsv11_enabled
- set_tlsv12_enabled
- set_compression_enabled
- set_default_workarounds_enabled
- set_certificate
- set_certificate_authority_pool
- set_passphrase
- set_private_key
- set_private_rsa_key
- set_temporary_diffie_hellman
#### SSLSettings::constructor
SSLSettings( void );
Initialises a new class instance; see also destructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::destructor
virtual ~SSLSettings( void );
Clean-up class instance; see also constructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
No exceptions allowed specification: noexcept.
#### SSLSettings::has_disabled_http
bool has_disabled_http( void ) const;
Determine if HTTP has been disabled and that the service should only listen for incoming HTTPS requests.##### Parameters
n/a
##### Return Value
Boolean indicating that HTTP has been disabled.
##### Exceptions
n/a
#### SSLSettings::has_enabled_sslv2
bool has_enabled_sslv2( void ) const;
Determine if SSLv2 has been enabled.##### Parameters
n/a
##### Return Value
Boolean indicating SSLv2 is enabled.
##### Exceptions
n/a
#### SSLSettings::has_enabled_sslv3
bool has_enabled_sslv3( void ) const;
Determine if SSLv3 has been enabled.##### Parameters
n/a
##### Return Value
Boolean indicating SSLv3 is enabled.
##### Exceptions
n/a
#### SSLSettings::has_enabled_tlsv1
bool has_enabled_tlsv1( void ) const;
Determine if TLSv1 has been enabled.##### Parameters
n/a
##### Return Value
Boolean indicating TLSv1 is enabled.
##### Exceptions
n/a
#### SSLSettings::has_enabled_tlsv11
bool has_enabled_tlsv11( void ) const;
Determine if TLSv1.1 has been enabled.##### Parameters
n/a
##### Return Value
Boolean indicating TLSv1.1 is enabled.
##### Exceptions
n/a
#### SSLSettings::has_enabled_tlsv12
bool has_enabled_tlsv12( void ) const;
Determine if TLSv1.2 has been enabled.##### Parameters
n/a
##### Return Value
Boolean indicating TLSv1.2 is enabled.
##### Exceptions
n/a
#### SSLSettings::has_enabled_compression
bool has_enabled_compression( void ) const;
Determine if compression has been enabled.##### Parameters
n/a
##### Return Value
Boolean indicating compression is enabled.
##### Exceptions
n/a
#### SSLSettings::has_enabled_default_workarounds
bool has_enabled_default_workarounds( void ) const;
Determine if the default workarounds are enabled.##### Parameters
n/a
##### Return Value
Boolean indicating default workaround enabled.
##### Exceptions
n/a
#### SSLSettings::has_enabled_single_diffie_hellman_use
bool has_enabled_single_diffie_hellman_use( void ) const;
Determine if single Diffie-Hellman use is enabled.##### Parameters
n/a
##### Return Value
Boolean indicating single Diffie-Hellman use.
##### Exceptions
n/a
#### SSLSettings::get_port
uint16_t get_port( void ) const;
Retrieves the network port number on which the service will listen.##### Parameters
n/a
##### Return Value
uint16_t representing the network port number.
##### Exceptions
n/a
#### SSLSettings::get_bind_address
std::string get_bind_address( void ) const;
Retrieves the local network interface card address to attach the service.##### Parameters
n/a
##### Return Value
std::string detailing the service bind address.
##### Exceptions
n/a
#### SSLSettings::get_certificate
std::string get_certificate( void ) const;
Retrieves the filename of the SSL certificate.##### Parameters
n/a
##### Return Value
std::string certificate filename.
##### Exceptions
n/a
#### SSLSettings::get_passphrase
std::string get_passphrase( void ) const;
Retrieves SSL certificate passphrase.##### Parameters
n/a
##### Return Value
std::string certificate passphrase.
##### Exceptions
n/a
#### SSLSettings::get_private_key
std::string get_private_key( void ) const;
Retrieves the filename of the private key.##### Parameters
n/a
##### Return Value
std::string private key filename.
##### Exceptions
n/a
#### SSLSettings::get_private_rsa_key
std::string get_private_rsa_key( void ) const;
Retrieves the filename of the RSA private key.##### Parameters
n/a
##### Return Value
std::string certificate filename.
##### Exceptions
n/a
#### SSLSettings::get_certificate_chain
std::string get_certificate_chain( void ) const;
Retrieves the filename of the certificate chain.##### Parameters
n/a
##### Return Value
std::string certificate chain filename.
##### Exceptions
n/a
#### SSLSettings::get_temporary_diffie_hellman
std::string get_temporary_diffie_hellman( void ) const;
Retrieves the filename for the temporary Diffie-Hellman.##### Parameters
n/a
##### Return Value
std::string diffie hellman filename.
##### Exceptions
n/a
#### SSLSettings::get_certificate_authority_pool
std::string get_certificate_authority_pool( void ) const;
Retrieves the filename from the certificate authority pool.##### Parameters
n/a
##### Return Value
std::string diffie hellman filename.
##### Exceptions
n/a
#### SSLSettings::set_port
void set_port( const uint16_t value );
Set the network port on which the service should listen for incoming HTTPS requests.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | uint16_t | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_bind_address
void set_bind_address( const std::string& value );
Set the network interface card address with which the service should attach itself.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_http_disabled
void set_http_disabled( const bool value );
Set true to disable unencrypted HTTP service access.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | bool | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_sslv2_enabled
void set_sslv2_enabled( const bool value );
Set true to enable SSLv2.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | bool | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_sslv3_enabled
void set_sslv3_enabled( const bool value );
Set true to enable SSLv3.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | bool | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_tlsv1_enabled
void set_tlsv1_enabled( const bool value );
Set true to enable TLSv1.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | bool | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_tlsv11_enabled
void set_tlsv11_enabled( const bool value );
Set true to enable TLSv1.1.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | bool | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_tlsv12_enabled
void set_tlsv12_enabled( const bool value );
Set true to enable TLSv1.2.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | bool | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_compression_enabled
void set_compression_enabled( const bool value );
Set true to enable compression.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | bool | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_default_workarounds_enabled
void set_default_workarounds_enabled( const bool value );
Set true to enable default workarounds.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | bool | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_single_diffie_hellman_use_enabled
void set_single_diffie_hellman_use_enabled( const bool value );
Set true to enable single Diffie-Hellman use.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | bool | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_certificate
void set_certificate( const Uri& value );
Set the filename to the SSL certificate.##### Parameters
| name | type | default value | direction |
|:----------:|-------------|:-------------:|:---------:|
| value | Uri | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_certificate_chain
void set_certificate_chain( const Uri& value );
Set the filename to the SSL certificate chain.##### Parameters
| name | type | default value | direction |
|:----------:|-------------|:-------------:|:---------:|
| value | Uri | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_certificate_authority_pool
void set_certificate_authority_pool( const Uri& value );
Set the filename to the SSL certificate authority pool.##### Parameters
| name | type | default value | direction |
|:----------:|-------------|:-------------:|:---------:|
| value | Uri | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_passphrase
void set_passphrase( const std::string& value );
Set the filename to the SSL certificate passphrase.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_private_key
void set_private_key( const Uri& value );
Set the filename to the SSL private key.##### Parameters
| name | type | default value | direction |
|:----------:|-------------|:-------------:|:---------:|
| value | Uri | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_private_rsa_key
void set_private_rsa_key( const Uri& value );
Set the filename to the SSL private RSA key.##### Parameters
| name | type | default value | direction |
|:----------:|-------------|:-------------:|:---------:|
| value | Uri | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### SSLSettings::set_temporary_diffie_hellman
void set_temporary_diffie_hellman( const Uri& value );
Set the filename to temporary Diffie-Hellman.##### Parameters
| name | type | default value | direction |
|:----------:|-------------|:-------------:|:---------:|
| value | Uri | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
StatusCode
Enumeration of HTTP response status codes as outlined in RFC 7231 sub-section 6.1.
Uri
Represents a Uniform Resource Identifier as specified in RFC 3986.
#### Methods
- constructor
- destructor
- is_relative
- is_absolute
- to_string
- is_valid
- parse
- decode
- decode_parameter
- encode
- encode_parameter
- get_port
- get_path
- get_query
- get_scheme
- get_fragment
- get_username
- get_password
- get_authority
- get_query_parameters
#### Uri::constructor
explicit Uri( const std::string& value, bool relative = false );
Uri( const Uri& original );
Initialises a new class instance; see also destructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### Uri::destructor
virtual ~Uri( void );
Clean-up class instance; see also constructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
No exceptions allowed specification: noexcept.
#### Uri::is_relative
bool is_relative( void ) const;
Determines if the URI is a relative path.##### Parameters
n/a
##### Return Value
Boolean true if relative, else false.
##### Exceptions
n/a
#### Uri::is_absolute
bool is_absolute( void ) const;
Determines if the URI is an absolute path.##### Parameters
n/a
##### Return Value
Boolean true if relative, else false.
##### Exceptions
n/a
#### Uri::to_string
std::string to_string( void ) const;
Convert the Uri instance to a string representation.##### Parameters
n/a
##### Return Value
std::string representing the URI's contents.
##### Exceptions
n/a
#### Uri::is_valid
static bool is_valid( const std::string& value );
Determines if the supplied string is a valid URI.##### Parameters
n/a
##### Return Value
Boolean true if valid, else false.
##### Exceptions
n/a
#### Uri::parse
static Uri parse( const std::string& value );
Parse the string to a URI instance.##### Parameters
| name | type | default value | direction |
|:----------:|---------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
Uri instance.
##### Exceptions
n/a
#### Uri::decode
static std::string decode( const std::string& value );
URL percent-decoding functionality.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
Decoded std::string value.
##### Exceptions
n/a
#### Uri::decode_parameter
static std::string decode_parameter( const std::string& value );
URL parameter percent-decoding functionality.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
Decoded std::string value.
##### Exceptions
n/a
#### Uri::encode
static std::string encode( const std::string& value );
URL percent-encoding functionality.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
Encoded std::string value.
##### Exceptions
n/a
#### Uri::encode_parameter
static std::string encode_parameter( const std::string& value );
URL parameter percent-encoding functionality.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
Encoded std::string value.
##### Exceptions
n/a
#### Uri::get_port
uint16_t get_port( void ) const;
Retrieves the network port number.##### Parameters
n/a
##### Return Value
uint16_t representing the network port number.
##### Exceptions
n/a
#### Uri::get_path
std::string get_path( void ) const;
Retrieves the path segment.##### Parameters
n/a
##### Return Value
Path segment as a std::string.
##### Exceptions
n/a
#### Uri::get_query
std::string get_query( void ) const;
Retrieves the query segment.##### Parameters
n/a
##### Return Value
Query segment as a std::string.
##### Exceptions
n/a
#### Uri::get_scheme
std::string get_scheme( void ) const;
Retrieves the scheme segment.##### Parameters
n/a
##### Return Value
Scheme segment as a std::string.
##### Exceptions
n/a
#### Uri::get_fragment
std::string get_fragment( void ) const;
Retrieves the fragment segment.##### Parameters
n/a
##### Return Value
Scheme segment as a std::string.
##### Exceptions
n/a
#### Uri::get_username
std::string get_username( void ) const;
Retrieves the username segment.##### Parameters
n/a
##### Return Value
Username segment as a std::string.
##### Exceptions
n/a
#### Uri::get_password
std::string get_password( void ) const;
Retrieves the password segment.##### Parameters
n/a
##### Return Value
Password segment as a std::string.
##### Exceptions
n/a
#### Uri::get_authority
std::string get_authority( void ) const;
Retrieves the authority segment.##### Parameters
n/a
##### Return Value
Authority segment as a std::string.
##### Exceptions
n/a
#### Uri::get_query_parameters
std::multimap< std::string, std::string > get_query_parameters( void ) const;
Retrieves parsed query parameters.##### Parameters
n/a
##### Return Value
std::multimap of decoded query parameters.
##### Exceptions
n/a
WebSocket
Represents a WebSocket.
#### Methods
- constructor
- destructor
- is_open
- is_closed
- close
- send
- get_key
- get_logger
- get_open_handler
- get_close_handler
- get_error_handler
- get_message_handler
- set_key
- set_logger
- set_open_handler
- set_close_handler
- set_error_handler
- set_message_handler
#### WebSocket::constructor
WebSocket( void );
Initialises a new class instance; see also destructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocket::destructor
virtual ~WebSocket( void );
Clean-up class instance; see also constructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
No exceptions allowed specification: noexcept.
#### WebSocket::is_open
bool is_open( void ) const;
Determine if the underlying socket is active.##### Parameters
n/a
##### Return Value
Boolean value indicating the socket is active.
##### Exceptions
n/a
#### WebSocket::is_open
bool is_closed( void ) const;
Determine if the underlying socket is inactive.##### Parameters
n/a
##### Return Value
Boolean value indicating the socket is inactive.
##### Exceptions
n/a
#### WebSocket::close
void close( void );
Close the socket.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocket::send
void send( const Bytes& body, const std::function< void ( const std::shared_ptr< WebSocket > ) > callback = nullptr );
void send( const std::string& body, const std::function< void ( const std::shared_ptr< WebSocket > ) > callback = nullptr );
void send( const WebSocketMessage::OpCode opcode, const std::function< void ( const std::shared_ptr< WebSocket > ) > callback = nullptr );
void send( const std::shared_ptr< WebSocketMessage > message, const std::function< void ( const std::shared_ptr< WebSocket > ) > callback = nullptr );
Transmit a WebSocket message.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocket::get_key
std::string get_key( void ) const;
Retrieve a unique key identifying this instance.##### Parameters
n/a
##### Return Value
std::string unique identifier.
##### Exceptions
n/a
#### WebSocket::get_logger
std::shared_ptr< Logger > get_logger( void ) const;
Retrieve the logging instance used by this WebSocket.##### Parameters
n/a
##### Return Value
std::shared_ptr referencing Logger used.
##### Exceptions
n/a
#### WebSocket::get_open_handler
std::function< void ( const std::shared_ptr< WebSocket > ) > get_open_handler( void ) const;
Retrieve the open socket handler.##### Parameters
n/a
##### Return Value
std::function holding socket open handler.
##### Exceptions
n/a
#### WebSocket::get_close_handler
std::function< void ( const std::shared_ptr< WebSocket > ) > get_close_handler( void ) const;
Retrieve the socket closed handler.##### Parameters
n/a
##### Return Value
std::function holding socket close handler.
##### Exceptions
n/a
#### WebSocket::get_error_handler
std::function< void ( const std::shared_ptr< WebSocket >, const std::error_code ) > get_error_handler( void ) const;
Retrieve socket error handler.##### Parameters
n/a
##### Return Value
std::function holding socket error handler.
##### Exceptions
n/a
#### WebSocket::get_message_handler
std::function< void ( const std::shared_ptr< WebSocket >, const std::shared_ptr< WebSocketMessage > ) > get_message_handler( void ) const;
Retrieve socket message handler.##### Parameters
n/a
##### Return Value
std::function holding socket message handler.
##### Exceptions
n/a
#### WebSocket::set_key
void set_key( const std::string& value );
Set the WebSocket unique key.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocket::set_logger
void set_logger( const std::shared_ptr< Logger >& value );
Set Logger instance to use internally by the instance.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::shared_ptr | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocket::set_open_handler
void set_open_handler( const std::function< void ( const std::shared_ptr< WebSocket > ) >& value );
Set a callback to be invoked once the socket connection has been established to a remote endpoint.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocket::set_close_handler
void set_close_handler( const std::function< void ( const std::shared_ptr< WebSocket > ) >& value );
Set a callback to be invoked once the socket connection has been terminated.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocket::set_error_handler
void set_error_handler( const std::function< void ( const std::shared_ptr< WebSocket >, const std::error_code ) >& value );
Set a callback to be invoked if the socket encounters an error.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocket::set_message_handler
void set_message_handler( const std::function< void ( const std::shared_ptr< WebSocket >, const std::shared_ptr< WebSocketMessage > ) >& value );
Set a callback to be invoked when a message is received.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::function | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
WebSocketMessage
Class to abstract the over-engineered WebSocket packet format.
#### Methods
- constructor
- destructor
- to_bytes
- get_data
- get_opcode
- get_mask
- get_length
- get_extended_length
- get_mask_flag
- get_final_frame_flag
- get_reserved_flags
- set_data
- set_opcode
- set_mask
- set_length
- set_extended_length
- set_mask_flag
- set_final_frame_flag
- set_reserved_flags
#### WebSocketMessage::constructor
WebSocketMessage( void );
WebSocketMessage( const WebSocketMessage& original );
WebSocketMessage( const OpCode code, const Bytes& data = { } );
WebSocketMessage( const OpCode code, const std::string& data );
WebSocketMessage( const OpCode code, const Bytes& data, const std::uint32_t mask );
WebSocketMessage( const OpCode code, const std::string& data, const std::uint32_t mask );
Initialises a new class instance; see also destructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocketMessage::destructor
virtual ~WebSocketMessage( void );
Clean-up class instance; see also constructor.##### Parameters
n/a
##### Return Value
n/a
##### Exceptions
No exceptions allowed specification: noexcept.
#### WebSocketMessage::to_bytes
Bytes to_bytes( void ) const;
Convert instance to a collection of Bytes##### Parameters
n/a
##### Return Value
Bytes containing a representation of the current WebSocketMessage state.
##### Exceptions
n/a
#### WebSocketMessage::get_data
Bytes get_data( void ) const;
Get the data segment.##### Parameters
n/a
##### Return Value
Bytes containing message data.
##### Exceptions
n/a
#### WebSocketMessage::get_opcode
OpCode get_opcode( void ) const;
Get the operation code.##### Parameters
n/a
##### Return Value
WebSocketMessage::OpCode detailing operation code in use.
##### Exceptions
n/a
#### WebSocketMessage::get_mask
std::uint32_t get_mask( void ) const;
Get message mask.##### Parameters
n/a
##### Return Value
std::uint32_t detailing message length.
##### Exceptions
n/a
#### WebSocketMessage::get_length
std::uint8_t get_length( void ) const;
Get message data length.##### Parameters
n/a
##### Return Value
std::uint8_t detailing the mask to use on message data.
##### Exceptions
n/a
#### WebSocketMessage::get_extended_length
std::uint64_t get_extended_length( void ) const;
Get message data extended length.##### Parameters
n/a
##### Return Value
std::uint64_t detailing message extended length.
##### Exceptions
n/a
#### WebSocketMessage::get_mask_flag
bool get_mask_flag( void ) const;
Get a flag indicating if a mask is in use.##### Parameters
n/a
##### Return Value
Boolean indicating a mask is in use.
##### Exceptions
n/a
#### WebSocketMessage::get_mask_flag
bool get_final_frame_flag( void ) const;
Get a flag indicating if this message is the final frame.##### Parameters
n/a
##### Return Value
Boolean indicating a final frame.
##### Exceptions
n/a
#### WebSocketMessage::get_reserved_flags
std::tuple< bool, bool, bool > get_reserved_flags( void ) const;
Get reserved flags.##### Parameters
n/a
##### Return Value
std::tuple of reserved flags.
##### Exceptions
n/a
#### WebSocketMessage::set_data
void set_data( const Bytes& value );
void set_data( const std::string& value );
Set a callback to be invoked when a message is received.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | Bytes | n/a | input |
| value | std::string | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocketMessage::set_opcode
void set_opcode( const OpCode value );
Set message operation code.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | WebSocketMessage::OpCode | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocketMessage::set_mask
void set_mask( const std::uint32_t value );
Set message mask, this will also set the mask flag equal to true.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::uint32_t | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocketMessage::set_length
void set_length( const std::uint8_t value );
Set message length.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::uint8_t | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocketMessage::set_extended_length
void set_extended_length( const std::uint64_t value );
Set message extended length.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | std::uint64_t | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocketMessage::set_extended_length
void set_mask_flag( const bool value );
Setting true indicates a message mask is in place.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | Boolean | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocketMessage::set_final_frame_flag
void set_final_frame_flag( const bool value );
Setting true indicates this is the final frame in a sequence of messages.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| value | Boolean | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocketMessage::set_reserved_flags
void set_reserved_flags( const bool rsv1, const bool rsv2, const bool rsv3 );
Set reserved flags.##### Parameters
| name | type | default value | direction |
|:----------:|-------------------------------------------------------------------------------|:-------------:|:---------:|
| rsv1 | Boolean | n/a | input |
| rsv2 | Boolean | n/a | input |
| rsv3 | Boolean | n/a | input |
##### Return Value
n/a
##### Exceptions
n/a
#### WebSocketMessage::OpCode
class WebSocketMessage
{
enum OpCode : uint8_t
{
CONTINUATION_FRAME = 0x00,
TEXT_FRAME = 0x01,
BINARY_FRAME = 0x02,
CONNECTION_CLOSE_FRAME = 0x08,
PING_FRAME = 0x09,
PONG_FRAME = 0x0A
};
}
Enumeration detailing WebSocket message operation codes.###Β Further Reading
C++ Standard - The current ISO C++ standard is officially known as ISO International Standard ISO/IEC 14882:2014(E) β Programming Language C++. Want to read the ISO C++ standard, or working drafts of the standard? You have several options, most of them free.
C++ Reference - Comprehensive C++ and Standard Template Library (STL) reference.
Effective STL - Written for the intermediate or advanced C++ programmer, renowned C++ expert Scott Meyers provides essential techniques for getting more out of the Standard Template Library in Effective STL, a tutorial for doing more with this powerful library.
Effective C++ - βEvery C++ professional needs a copy of Effective C++. It is an absolute must-read for anyone thinking of doing serious C++ development. If youβve never read Effective C++ and you think you know everything about C++, think again.β β Steve Schirripa, Software Engineer, Google.
---
DESIGN
Overview
--------
This document is intended to communicate core architectural decisions within the system. For this reason alone, accuracy has suffered. It does not concern itself with interface specifics and primarily focuses on architectural decisions made during the design and development phase. See API for contract details.
All class definitions within the system strictly adhere to the Opaque Pointer idiom. However, this level of detail in the following suite of class diagrams is omitted for clarity, along with pointers, references and other background noise.
Unless otherwise specified, all primary data-types originate within the Standard Template Library (STL).
Interpretation
--------------
The key words βMUSTβ, βMUST NOTβ, βREQUIREDβ, βSHALLβ, βSHALL NOTβ, βSHOULDβ, βSHOULD NOTβ, βRECOMMENDEDβ, βMAYβ, and βOPTIONALβ in this document are to be interpreted as described in RFC 2119.
Table of Contents
-----------------
1. Overview
2. Interpretation
3. Terminology
4. System Entities
5. Entity Interactions
6. Dependency Tree
7. Event Loop
8. Thread Allocation
9. Future Direction
10. Further Reading
Terminology
-----------
| Term | Definition |
|--------------|-----------------------------------------------------------------------------------------------------------------------------|
| Resource | A network addressable entity, i.e Queue. |
| Service | A server responsible for request routing and processing. |
| Client | A remote endpoint responsible for generating requests. |
| Logger | A component making a systematic recording of events, observations, or measurements. |
| Charset | A CHARacter SET is used to represent a repertoire of symbols, i.e UTF-8. |
| URI | Uniform Resource Identifier. |
| UUID | Universally Unique IDentifier. |
| Path | String identifier uniquely addressing a resource. |
System Entities
---------------
- Bytes
- Resource
- Callback
- StatusCode
- String::Option
- String
- URI
- Request
- Response
- Session
- SSLSettings
- Settings
- WebSocket
- WebSocketMessage
- WebSocketMessage::OpCode
- Logger
- Logger::Level
- Service
Bytes
Bytes provides container functionality with STL vector collection semantics.
Resource
Resource represents a network communication endpoint. This is the primary data-structure used throughout to represent RESTful resources. All resource-specific filtration, request processing, and authentication must be placed on this entity.
+------------------------------------------------------------------------+
| <<class>> |
| Resources |
+------------------------------------------------------------------------+
| + set_path(string) void |
| + set_paths(set<string>) void |
| + set_default_header(string,string) void |
| + set_default_headers(multimap<string,string>) void |
| + set_error_handler(Callback) void |
| + set_authentication_handler(void) void |
| + set_method_handler(string,Callback) void |
+------------------------------------------------------------------------+
Callback
Represents a functor with variable parameters and return value; this is used to help illustrate the design without introducing unnecessary complexity.
+-----------------+
| <<typedef>> |
| Callback |
+-----------------+
| std::function |
+-----------------+
StatusCode
Enumeration of HTTP response status codes as outlined in RFC 7231 sub-section 6.1.
+---------------------------+
| <<enum>> |
| StatusCode |
+---------------------------+
| See RFC 7231 for details. |
+---------------------------+
String::Option
Enumeration of possible string case sensitivity options.
+--------------------+
| <<enum>> |
| String::Option |
+--------------------+
| + CASE_SENSITIVE |
| + CASE_INSENSITIVE |
+------------------ -+
String
Utility class with static scope offering a common suite of string manipulation routines.
+---------------------------------------------------------------+
| <<static>> |
| String |
+---------------------------------------------------------------+
| + to_bytes(string) Bytes |
| + lowercase(string) string |
| + uppercase(string,string) string |
| + format(char*,...) string |
| + join(multimap<string,string>,string,string) string |
| + remove(string,string,Option) string |
| + replace(string,string,string,Option) string |
| + split(string,string) vector<string> |
+--------------------------------^------------------------------+
|
|
|
+----------------v----------------+
| <<enum>> |
| String::Option |
+---------------------------------+
| See String::Option for details. |
+---------------------------------+
URI
Represents a Uniform Resource Identifier as specified in RFC 3986.
A generic URI is of the form:
> scheme:[//[user:password@]host\[:port]][/]path[?query][#fragment]
+-------------------------------------------------------+
| <<class>> |
| Uri |
+-------------------------------------------------------+
| + is_relative(void) boolean |
| + is_absolute(void) boolean |
| + is_valid(string) boolean |
| + parse(string) Uri |
| + to_string(void) string |
| + decode(string) string |
| + decode_parameter(string) string |
| + encode(string) string |
| + encode_parameter(string) string |
| + get_port(void) unsigned 16-bit integer |
| + get_path(void) string |
| + get_query(void) string |
| + get_scheme(void) string |
| + get_fragment(void) string |
| + get_username(void) string |
| + get_password(void) string |
| + get_authority(void) string |
| + get_query_parameters(void) multimap<string,string> |
+-------------------------------------------------------+
Request
Represents an HTTP request with additional helper methods for manipulating data and code readability.
/ Detailed source-code truncated for AI context efficiency. /
Response
Represents an HTTP response with additional helper methods for manipulating data and improving code readability.
/ Detailed source-code truncated for AI context efficiency. /
Session
Represents a conversation between a client and the service. Internally, this class holds the network state and exposes public functionality to interact with the service event-loop for asynchronous data acquisition and/or sleep states.
/ Detailed source-code truncated for AI context efficiency. /
SSLSettings
Represents Secure Socket Layer service configuration.
/ Detailed source-code truncated for AI context efficiency. /
Settings
Represents the primary point of Service and Logger configuration.
/ Detailed source-code truncated for AI context efficiency. /
WebSocket
Represents a WebSocket connection. Internally, this class holds the network state and exposes public functionality for full-duplex client interaction.
/ Detailed source-code truncated for AI context efficiency. /
WebSocketMessage
Class representing a single WebSocket data message.
/ Detailed source-code truncated for AI context efficiency. /
WebSocketMessage::OpCode
Enumeration is used in conjunction with the WebSocket and WebSocketMessage to detail the message category.
+--------------------------+
| <<enum>> |
| WebSocketMessage::OpCode |
+--------------------------+
| CONTINUATION_FRAME |
| TEXT_FRAME |
| BINARY_FRAME |
| CONNECTION_CLOSE_FRAME |
| PING_FRAME |
| PONG_FRAME |
+--------------------------+
Logger
Interface detailing the required contract for logger extensions. No default logger is supplied with the codebase; it is the responsibility of third-party developers to implement the desired characteristics.
+-----------------------------------------------+
| <<interface>> |
| Logger |
+-----------------------------------------------+
| + stop(void) void |
| + start(Settings) void |
| + log(Logger::Level,string) void |
| + log_if(condition,Logger::Level,string) void |
+----------------------^------------------------+
|
|
|
+---------------v----------------+
| <<enum>> |
| Logger::Level |
+--------------------------------+
| See Logger::Level for details. |
+--------------------------------+
Logger::Level
Enumeration is used in conjunction with the Logger interface to detail the level of severity towards a particular log entry.
+---------------+
| <<enum>> |
| Logger::Level |
+---------------+
| INFO |
| DEBUG |
| FATAL |
| ERROR |
| WARNING |
| SECURITY |
+---------------+
Service
The service is responsible for managing the publicly available RESTful resources, HTTP compliance, scheduling of the socket data and ensuring incoming requests are processed in a timely fashion.
/ Detailed source-code truncated for AI context efficiency. /
Entity Interactions
-------------------Request Processing
/ Detailed source-code truncated for AI context efficiency. /
Dependency Tree
---------------+----------------------------+
| Restbed |
+----------------------------+
| Asynchronous Web Framework |
+----------------------------+
|
+------------------+------------------+
| |
+--------------------+ +----------------------+
| ASIO | | OpenSSL |
+--------------------+ +----------------------+
| Asynchronous I/O . | | Secure Socket Layer. |
+--------------------+ +----------------------+
Event LoopSettings::set_worker_limit
----------The asynchronous nature of the framework is achieved by employing an event-reaction loop, allowing Non-Block I/O and timed waits for external stimuli. This architectural decision allows the framework to scale and address the C10K Problem, all the while keeping resource consumption to a minimum and optimising thread allocation.
Thread allocation
-----------------By default, the framework will only allocate a single thread to process all incoming requests and scheduled workloads. This can be increased by altering the
attribute. It is recommended that you should not exceed the available hardware limit. See below for a suggested implementation.
#include <thread>
#include <cstdlib>
#include <restbed>
using namespace restbed;
int main( const int, const char )
{
auto resource = make_shared< Resource >( );
resource->set_path( "/resource" );
resource->set_method_handler( "GET", get_method_handler );
auto settings = make_shared< Settings >( );
settings->set_worker_limit( std::thread::hardware_concurrency( ) );
Service service;
service.publish( resource );
service.start( settings );
return EXIT_SUCCESS;
}
``
Future Direction
----------------
It is the aim of the core development team to remove ASIO as a dependency due to the tight coupling of IO and Event Loop principles. This setup leads to cross-contamination of concerns and forces design decisions on dependents.
WebSocketManager and ResourceCache shall be exposed for customisation by third-party developers.
Application Layer (HTTP, HTTP2, SPDY, etc) will be exposed for customisation by third-party developers.
Network Layer (TCP, UDP, RS232, etc) shall be exposed for customisation by third-party developers.
The secure socket logic layer will allow alternative implementations, such as OpenSSL, GnuTLS, PolarSSL, MatrixSSL, etc.
Further Reading
---------------
Opaque Pointer - In computer programming, an opaque pointer is a special case of an opaque data type, a datatype declared to be a pointer to a record or data structure of some unspecified type.
Uniform Resource Identifier (URI): Generic Syntax - A Uniform Resource Identifier (URI) is a compact sequence of characters that identifies an abstract or physical resource. This specification defines the generic URI syntax and a process for resolving URI references that might be in relative form, along with guidelines and security considerations for the use of URIs on the Internet. The URI syntax defines a grammar that is a superset of all valid URIs, allowing an implementation to parse the common components of a URI reference without knowing the scheme-specific requirements of every possible identifier. This specification does not define a generative grammar for URIs; that task is performed by the individual specifications of each URI scheme.
C10K Problem - The C10K Problem refers to the inability of a server to scale beyond 10,000 connections or clients due to resource exhaustion. Servers that employ the thread-per-client model, for example, can be confounded when pooled threads spend too much time waiting on blocking operations.
ASIO - Asio is a cross-platform C++ library for network and low-level I/O programming that provides developers with a consistent asynchronous model using a modern C++ approach.
Eventloop - In computer science, the event loop, message dispatcher, message loop, message pump, or run loop is a programming construct that waits for and dispatches events or messages in a program. It works by requesting some internal or external "event provider" (that generally blocks the request until an event has arrived), and then it calls the relevant event handler ("dispatches the event"). The event-loop may be used in conjunction with a reactor if the event provider follows the file interface, which can be selected or 'polled' (the Unix system call, not actual polling). The event loop almost always operates asynchronously with the message originator.
---