StupidBeauty
Read times:1322Posted at: - no title specified

Tufao 1.2.1文档翻译 Tufao::HttpServerPlugin 类参考 ,Tufao::HttpServerPlugin Class Reference

这个类,提供了一个工厂接口,用于创建请求处理器,以及,与其它插件的工厂进行通信。 详细说明……

详细说明

这个类,提供了一个工厂接口,用于创建请求处理器,以及,与其它插件的工厂进行通信。

以下是一个示例:

#ifndef PLUGIN_H

#define PLUGIN_H

#include <Tufao/HttpServerPlugin>

class Plugin: public QObject, Tufao::HttpServerPlugin

{

Q_OBJECT

Q_PLUGIN_METADATA(IID TUFAO_HTTPSERVERPLUGIN_IID )

Q_INTERFACES( Tufao::HttpServerPlugin )

public:

std::function<bool(Tufao::HttpServerRequest&, Tufao::HttpServerResponse&)>

createHandler (const QHash<QString, Tufao::HttpServerPlugin*> &dependencies,

const QVariant &customData = QVariant()) override;

};

#endif // PLUGIN_H

这是实现文件:

#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;

};

}

参考

TUFAO_HTTPSERVERPLUGIN_IID

自此版本开始引入

1.0

成员函数文档

virtual std::function<bool( HttpServerRequest &, HttpServerResponse &)> Tufao::HttpServerPlugin::createHandler

(

const QHash< QString,  HttpServerPlugin  * > & 

dependencies ,

const QVariant & 

customData  =  QVariant()

)

pure virtual

创建一个持久处理器。

注意

所创建的处理器会被用 HttpServerRequestRouter::map 中的参数。如果 妳希望对于每个请求 都使用不同的处理器的话,那么 ,妳应当在所返回的处理器代码体中创建 另一个处理器。

刚小希

Your opinions

Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands