tufao  1.3.0
An asynchronous web framework for C++ built on top of Qt
Tufao::HttpServerPlugin Class Referenceabstract

This class provides a factory interface to create request handlers and comunicate with factories of other plugins. More...

+ Collaboration diagram for Tufao::HttpServerPlugin:

Public Member Functions

virtual std::function< bool(HttpServerRequest &, HttpServerResponse &)> createHandler (const QHash< QString, HttpServerPlugin * > &dependencies, const QVariant &customData=QVariant())=0
 Creates a persistent handler. More...
 

Detailed Description

This class provides a factory interface to create request handlers and comunicate with factories of other plugins.

An example follows:

#ifndef PLUGIN_H
#define PLUGIN_H
#include <Tufao/HttpServerPlugin>
class Plugin: public QObject, Tufao::HttpServerPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID TUFAO_HTTPSERVERPLUGIN_IID)
public:
std::function<bool(Tufao::HttpServerRequest&, Tufao::HttpServerResponse&)>
createHandler(const QHash<QString, Tufao::HttpServerPlugin*> &dependencies,
const QVariant &customData = QVariant()) override;
};
#endif // PLUGIN_H

And its implementation file:

#include "plugin.h"
#include <QtCore/QtPlugin>
#include <Tufao/HttpServerResponse>
using namespace Tufao;
std::function<bool(HttpServerRequest&, HttpServerResponse&)>
Plugin::createHandler(const QHash<QString, HttpServerPlugin*> &,
const QVariant &)
{
return [](HttpServerRequest &, HttpServerResponse &res){
res.writeHead(HttpResponseStatus::OK);
res << "Responding from a evil plugin\n";
res.end();
return true;
};
}
See also
TUFAO_HTTPSERVERPLUGIN_IID
Since
1.0

Member Function Documentation

virtual std::function<bool(HttpServerRequest&, HttpServerResponse&)> Tufao::HttpServerPlugin::createHandler ( const QHash< QString, HttpServerPlugin * > &  dependencies,
const QVariant &  customData = QVariant() 
)
pure virtual

Creates a persistent handler.

Note
The handler created will be used as argument in HttpServerRequestRouter::map. If you want to use a different handler to every request, you should create another handler in the body of the returned handler.

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