tufao
1.3.0
An asynchronous web framework for C++ built on top of Qt
|
This class provides a robust and high performance HTTP request router. More...
Classes | |
struct | Mapping |
This class describes a request handler and a filter. More... | |
Public Types | |
typedef std::function< bool(HttpServerRequest &, const QByteArray &head)> | Handler |
It's a simple typedef for the type of handler accepted by the HttpUpgradeRouter. More... | |
Public Slots | |
bool | handleUpgrade (Tufao::HttpServerRequest &request, const QByteArray &head) override |
It will route the request to the right handler. More... | |
Public Member Functions | |
HttpUpgradeRouter (QObject *parent=0) | |
Constructs a HttpServerRequestRouter object. | |
HttpUpgradeRouter (std::initializer_list< Mapping > mappings, QObject *parent=0) | |
Constructs a HttpServerRequestRouter object initialized with mappings . | |
~HttpUpgradeRouter () | |
Destroys the object. | |
int | map (Mapping map) |
Chain map to the list of handlers available to handle requests. More... | |
int | map (std::initializer_list< Mapping > map) |
Chain map to the list of handlers available to handle requests. More... | |
void | unmap (int index) |
Removes the mapping at index . | |
void | clear () |
Removes all mappings. | |
Public Member Functions inherited from Tufao::AbstractHttpUpgradeHandler | |
operator std::function< bool (HttpServerRequest &, const QByteArray &)>() | |
Implicit conversion operator to std::function functor object. More... | |
operator std::function< void (HttpServerRequest &, const QByteArray &)>() | |
Implicit conversion operator to std::function functor object. More... | |
virtual bool | handleUpgrade (Tufao::HttpServerRequest &request, const QByteArray &head)=0 |
Handles the HTTP request . More... | |
This class provides a robust and high performance HTTP request router.
It allows to register a chain of upgrade handlers. This router uses mapping rules based on the url's path component to determine the correct handlers.
The type of mapping rules used in this class provides a predictable behaviour that is simple to understand and allow the use of caching algorithms to improve the performance.
When the router finds one matching request handler, it will call it. If the found handler cannot handle the request (this is indicated by the return value), the router will continue its quest in the search of a worthy handler. If the router fails in its quest (when no handlers are found or when none of the found handlers are able to respond the request), the handleRequest method in the router returns false and the connection remains open.
The code below provides an example usage:
typedef std::function<bool(HttpServerRequest&, const QByteArray &head)> Tufao::HttpUpgradeRouter::Handler |
It's a simple typedef for the type of handler accepted by the HttpUpgradeRouter.
|
overrideslot |
It will route the request to the right handler.
The handler will have access to the list of captured texts by the regular expression using HttpServerRequest::customData.
See example below:
If there is already an object set for this request, the router will do the following steps:
int Tufao::HttpUpgradeRouter::map | ( | Mapping | map | ) |
Chain map
to the list of handlers available to handle requests.
int Tufao::HttpUpgradeRouter::map | ( | std::initializer_list< Mapping > | map | ) |
Chain map
to the list of handlers available to handle requests.