httpgateway: set new max payload length config value
This commit is contained in:
parent
f7b8001546
commit
d02e8d0dce
15
config.cpp
15
config.cpp
@ -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);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
4
config.h
4
config.h
@ -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
|
||||
|
@ -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;
|
||||
|
@ -16,6 +16,7 @@ private:
|
||||
|
||||
std::string listenaddr;
|
||||
int listenport;
|
||||
uint64_t maxPayloadLength;
|
||||
public:
|
||||
HttpGateway(const Config &config);
|
||||
bool keepReading() override;
|
||||
|
Loading…
Reference in New Issue
Block a user