httpgateway: set new max payload length config value

This commit is contained in:
Albert S. 2019-05-04 00:02:17 +02:00
джерело f7b8001546
коміт d02e8d0dce
4 змінених файлів з 23 додано та 1 видалено

@ -53,6 +53,19 @@ int Config::optional(const std::string &key, int defaultvalue)
return defaultvalue; return defaultvalue;
} }
uint64_t Config::optional(const std::string &key, uint64_t defaultvalue)
{
auto it = this->configmap.find(key);
if(it != this->configmap.end())
{
std::string str = it->second;
return static_cast<uint64_t>(std::stoull(str));
}
return defaultvalue;
}
Config::Config(const std::map<std::string, std::string> &map) Config::Config(const std::map<std::string, std::string> &map)
{ {
@ -95,6 +108,8 @@ Config::Config(const std::map<std::string, std::string> &map)
this->templateprefix = "{qswiki:"; this->templateprefix = "{qswiki:";
this->max_payload_length = optional("max_payload_length", 10 *1024*1024);
} }

@ -14,6 +14,7 @@ private:
std::string optional(const std::string &key, std::string defaultvalue = ""); std::string optional(const std::string &key, std::string defaultvalue = "");
int optional(const std::string &key, int defaulvalue); int optional(const std::string &key, int defaulvalue);
uint64_t optional(const std::string &key, uint64_t defaultvalue);
public: public:
Config(const std::map<std::string, std::string> &map ); Config(const std::map<std::string, std::string> &map );
@ -51,6 +52,9 @@ public:
int session_max_lifetime; int session_max_lifetime;
int max_pagename_length; int max_pagename_length;
int threadscount; int threadscount;
uint64_t max_payload_length;
Permissions anon_permissions; Permissions anon_permissions;
std::string getConfig(const std::string &key) const std::string getConfig(const std::string &key) const

@ -33,6 +33,8 @@ HttpGateway::HttpGateway(const Config &config)
throw new std::runtime_error("No http.listenport in config file"); throw new std::runtime_error("No http.listenport in config file");
} }
this->listenport = std::stoi(listenport); this->listenport = std::stoi(listenport);
this->maxPayloadLength = config.max_payload_length;
} }
bool HttpGateway::keepReading() bool HttpGateway::keepReading()
@ -91,7 +93,7 @@ httplib::Response HttpGateway::convertResponse(Response response)
void HttpGateway::work(RequestWorker &worker) void HttpGateway::work(RequestWorker &worker)
{ {
httplib::Server server; httplib::Server server;
server.set_payload_max_length(this->maxPayloadLength);
auto handler = [&](const httplib::Request& req, httplib::Response& res) { auto handler = [&](const httplib::Request& req, httplib::Response& res) {
Request wikiRequest = convertRequest(req); Request wikiRequest = convertRequest(req);
Logger::debug() << "httpgateway: received request " << wikiRequest; Logger::debug() << "httpgateway: received request " << wikiRequest;

@ -16,6 +16,7 @@ private:
std::string listenaddr; std::string listenaddr;
int listenport; int listenport;
uint64_t maxPayloadLength;
public: public:
HttpGateway(const Config &config); HttpGateway(const Config &config);
bool keepReading() override; bool keepReading() override;