1
0

httpgateway: set new max payload length config value

Este cometimento está contido em:
Albert S. 2019-05-04 00:02:17 +02:00
ascendente f7b8001546
cometimento d02e8d0dce
4 ficheiros modificados com 23 adições e 1 eliminações

Ver ficheiro

@ -53,6 +53,19 @@ int Config::optional(const std::string &key, int 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)
{
@ -95,6 +108,8 @@ Config::Config(const std::map<std::string, std::string> &map)
this->templateprefix = "{qswiki:";
this->max_payload_length = optional("max_payload_length", 10 *1024*1024);
}

Ver ficheiro

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

Ver ficheiro

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

Ver ficheiro

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