tufao  0.8.1
An asynchronous web framework for C++ built on top of Qt
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Tufao::HttpUpgradeRouter Class Reference

This class provides a robust and high performance HTTP upgrade router. More...

+ Inheritance diagram for Tufao::HttpUpgradeRouter:
+ Collaboration diagram for Tufao::HttpUpgradeRouter:

Public Slots

bool handleRequest (Tufao::HttpServerRequest *request, const QByteArray &head, const QStringList &args=QStringList())
 It will route the request to the right handler. More...
 
- Public Slots inherited from Tufao::AbstractHttpUpgradeHandler
virtual bool handleRequest (Tufao::HttpServerRequest *request, const QByteArray &head, const QStringList &args=QStringList())=0
 Handles the HTTP upgrade request. More...
 

Public Member Functions

 HttpUpgradeRouter (QObject *parent=0)
 Constructs a HttpUpgradeRouter object.
 
 ~HttpUpgradeRouter ()
 Destroys the object.
 
HttpUpgradeRoutermap (const QRegExp &path, AbstractHttpUpgradeHandler *handler)
 This method maps requests which path components in the url matches the regular expression path to the given handler. More...
 
HttpUpgradeRouterunmap (const QRegExp &path, AbstractHttpUpgradeHandler *handler)
 Removes all mappings that correspond to path and handler rules and aren't specific to a particular HTTP method.
 
HttpUpgradeRouterunmap (const QRegExp &path)
 Removes all mappings that correspond to path rule.
 
HttpUpgradeRouterunmap (AbstractHttpUpgradeHandler *handler)
 Removes all mappings that correspond to handler rule.
 
void clear ()
 Removes all mappings.
 
- Public Member Functions inherited from Tufao::AbstractHttpUpgradeHandler
 AbstractHttpUpgradeHandler (QObject *parent=0)
 Constructs an AbstractHttpUpgradeHandler object.
 

Detailed Description

This class provides a robust and high performance HTTP upgrade router.

It allows register AbstractHttpUpgradeHandler objects to handle requests that matches the mapping rules. The mapping rules are limited to use regular expressions to filter the url path component.

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.

Did you note that HttpServerRequestRouter is a subclass of AbstractHttpUpgradeHandler? This design choice allows you to nest routes.

When the router finds one matching request handler, it will call its handleRequest method passing the request and head objects and also the captured texts by the regular expression. 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. This mean that you should always create a handler that closes any request as the last handler in the most top-level request router.

Since
0.6

Member Function Documentation

bool Tufao::HttpUpgradeRouter::handleRequest ( Tufao::HttpServerRequest request,
const QByteArray &  head,
const QStringList &  args = QStringList() 
)
slot

It will route the request to the right handler.

To route the request, it'll percent decode the path component from the url.

The args object is prepend in the list of captured texts by the regular expression and then passed to the handler. My advice is to don't overuse this feature or you will get a code difficult to understand.

Returns
Returns true if one handler able to respond the request is found.
HttpUpgradeRouter& Tufao::HttpUpgradeRouter::map ( const QRegExp &  path,
AbstractHttpUpgradeHandler handler 
)

This method maps requests which path components in the url matches the regular expression path to the given handler.

Returns
Returns itself, so you can create several mappings in the same line of code.

The documentation for this class was generated from the following file: